<commit_before>require 'fileutils'
require 'active_support/inflector'

module GrapeDoc
  class Generator
    def initialize(api_class, output_path)
      raise 'api_class must be specified' if api_class.nil?
      raise 'output_path must be specified' if output_path.nil?

      @output_path = output_path
      @api_class = api_class.constantize
    end

    def generate_namespace_docs
      docs = []

      @api_class.versions.each do |version|
        namespaces_for_version(version).each do |namespace|
          doc = NamespaceDoc.new
          doc.version = version
          doc.title = titleize(namespace)
          doc.root_path = namespace
          doc.routes = routes_for_version_and_namespace(version, namespace)
          doc.resources = resources_for_version(version)
          docs << doc
        end
      end

      docs
    end

    def output(format = 'html')
      files = {}
      generate_namespace_docs.each do |doc|
        puts doc.title

        filename = File.join(@output_path, doc.version, "#{doc.root_path}.#{format}")
        files[filename] = self.send("generate_#{format}", doc)
      end

      Writer.new(files).write_to_files!
    end

    private

    def generate_textile(doc)
      Formatters::Textile.new(doc).format
    end

    def generate_html(doc)
      Formatters::Html.new(doc).format
    end

    def resources_for_version(version)
      resources = []
      namespaces_for_version(version).each do |resource|<commit_msg>refactor to use initalizer instead<commit_after>require 'fileutils'
require 'active_support/inflector'

module GrapeDoc
  class Generator
    def initialize(api_class, output_path)
      raise 'api_class must be specified' if api_class.nil?
      raise 'output_path must be specified' if output_path.nil?

      @output_path = output_path
      @api_class = api_class.constantize
    end

    def generate_namespace_docs
      docs = []

      @api_class.versions.each do |version|
        namespaces_for_version(version).each do |namespace|
          docs << NamespaceDoc.new(:version => version,
                                   :title => titleize(namespace),
                                   :root_path => namespace,
                                   :routes => routes_for_version_and_namespace(version, namespace),
                                   :resources => resources_for_version(version))
        end
      end

      docs
    end

    def output(format = 'html')
      files = {}
      generate_namespace_docs.each do |doc|
        puts doc.title

        filename = File.join(@output_path, doc.version, "#{doc.root_path}.#{format}")
        files[filename] = self.send("generate_#{format}", doc)
      end

      Writer.new(files).write_to_files!
    end

    private

    def generate_textile(doc)
      Formatters::Textile.new(doc).format
    end

    def generate_html(doc)
      Formatters::Html.new(doc).format
    end

    def resources_for_version(version)
      resources = []
      namespaces_for_version(version).each do |resource|
{'fraction_non_alphanumeric': 0.08970976253298153, 'fraction_numerical': 0.0, 'mean_word_length': 2.430995475113122, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2070166', 'n_tokens_mistral': 882, 'n_tokens_neox': 858, 'n_words': 184}