<commit_before>require 'ridley'
require 'minimart/web/markdown_parser'

module Minimart
  class Cookbook

    def initialize(path_to_cookbook)
      @raw_cookbook = Ridley::Chef::Cookbook.from_path(path_to_cookbook)
    end

    def name
      raw_cookbook.cookbook_name
    end

    def version
      raw_cookbook.version
    end

    # Return a the cookbook name, and version number separated by a dash
    def to_s
      raw_cookbook.name
    end

    def description
      metadata.description
    end

    def maintainer
      metadata.maintainer
    end

    def path
      raw_cookbook.path
    end

    def web_friendly_version
      version.gsub('.', '_')
    end

    def dependencies
      metadata.dependencies
    end

    def readme_file
      @readme_file ||= find_file('readme')
    end

    def changelog_file
      @changelog_file ||= find_file('changelog')
    end

    def readme_content
      @readme_content ||= Web::MarkdownParser.parse(readme_file) if readme_file
    end

    def changelog_content
      @changelog_content ||= Web::MarkdownParser.parse(changelog_file) if changelog_file
    end

    private

    attr_reader :raw_cookbook

    def metadata
      raw_cookbook.metadata
    end

    def find_file(name)
      Dir.glob(File.join(path, '*')).find do |file|
        File.basename(file, File.extname(file)) =~ /\A#{name}\z/i
      end
    end

    def path_to_file(file)
      File.join(self.path, file)
    end
  end
end<commit_msg>Allowing cookbooks to be converted to JSON<commit_after>require 'ridley'
require 'minimart/web/markdown_parser'
require 'minimart/web/template_helper'

module Minimart
  class Cookbook
    include Web::TemplateHelper

    def initialize(path_to_cookbook)
      @raw_cookbook = Ridley::Chef::Cookbook.from_path(path_to_cookbook)
    end

    def name
      raw_cookbook.cookbook_name
    end

    def version
      raw_cookbook.version
    end

    # Return a the cookbook name, and version number separated by a dash
    def to_s
      raw_cookbook.name
    end

    def description
      metadata.description
    end

    def maintainer
      metadata.maintainer
    end

    def path
      raw_cookbook.path
    end

    def web_friendly_version
      version.gsub('.', '_')
    end

    def dependencies
      metadata.dependencies
    end

    def readme_file
      @readme_file ||= find_file('readme')
    end

    def changelog_file
      @changelog_file ||= find_file('changelog')
    end

    def readme_content
      @readme_content ||= Web::MarkdownParser.parse(readme_file) if readme_file
    end

    def changelog_content
      @changelog_content ||= Web::MarkdownParser.parse(changelog_file) if changelog_file
    end

    def to_hash
      {
        name:           name,
        version:        version,
        description:    description,
        maintainer:     maintainer,
        download_url:   cookbook_download_path(self),
        url:            cookbook_path(self)
      }
    end

    def to_json(opts = {})
      to_hash.to_json
    end

    private

    attr_reader :raw_cookbook

    def metadata
      raw_cookbook.metadata
    end

    def find_file(name)
      Dir.glob(File.join(path, '*')).find do |file|
        File.basename(file, File.extname(file)) =~ /\A#{name}\z/i
      end
    end

    def path_to_file(file)
      File.join(self.path, file)
    end
  end
end
{'fraction_non_alphanumeric': 0.07505191337881933, 'fraction_numerical': 0.0, 'mean_word_length': 2.4198782961460448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4086895', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1074, 'n_words': 240}