Class: RecordRoo::DataSource
- Inherits:
-
Object
- Object
- RecordRoo::DataSource
- Defined in:
- lib/record_roo.rb
Instance Method Summary collapse
-
#initialize(filepath) ⇒ DataSource
constructor
A new instance of DataSource.
- #model_generator(model_with_attributes) ⇒ Object
- #parse ⇒ Object
Constructor Details
#initialize(filepath) ⇒ DataSource
Returns a new instance of DataSource.
7 8 9 |
# File 'lib/record_roo.rb', line 7 def initialize filepath @filepath = filepath end |
Instance Method Details
#model_generator(model_with_attributes) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/record_roo.rb', line 16 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 |
#parse ⇒ Object
11 12 13 14 |
# File 'lib/record_roo.rb', line 11 def parse @adapter = Class.instance_eval adapter @adapter.parse @filepath end |