<commit_before>require "csv"
require "roo"
require "record_roo/version"

module RecordRoo
	class DataSource
	  def initialize filepath
	    @filepath = filepath
	  end

	  def parse
	    @adapter = Class.instance_eval adapter
	    @adapter.parse @filepath
	  end

	  def model_generator model_with_attributes
	    parse.drop(1).map do |row|
	      model = model_with_attributes[:model]
	      object = Hash[model_with_attributes[:attributes].map.with_index(0) do |attr, index|
	        [attr, row[index]]
	      end]
	      model.new(object)
	    end
	  end

	  private
	  def raw_extension
	    File.extname @filepath
	  end

	  def adapter
	    raw_extension.match(/\w+/).to_s.capitalize
	  end
	end

	class Xlsx
	  def self.parse filepath
	    CSV.parse Roo::Excelx.new(filepath).to_csv
	  end
	end

	class Xls
	  def self.parse filepath
	    CSV.parse Roo::Excel.new(filepath).to_csv
	  end
	end

	class Csv
	  def self.parse filepath
	    CSV.read filepath
	  end
	end
end
<commit_msg>Adds lazy loading of RecordRoo module classes<commit_after>require "csv"
require "roo"

module RecordRoo
  autoload :VERSION,    './record_roo/version'

  autoload :DataSource, './record_roo/data_source'

  autoload :Csv,        './record_roo/formats/csv'
  autoload :Xlsx,       './record_roo/formats/xlsx'
  autoload :Xls,        './record_roo/formats/xls'
end

{'fraction_non_alphanumeric': 0.09090909090909091, 'fraction_numerical': 0.0014781966001478197, 'mean_word_length': 2.8908045977011496, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7202592', 'n_tokens_mistral': 515, 'n_tokens_neox': 473, 'n_words': 110}