Class: Origami::Importer::Writer
- Inherits:
-
Object
- Object
- Origami::Importer::Writer
- Defined in:
- lib/origami-importer/writer.rb
Instance Attribute Summary collapse
-
#batch ⇒ Object
Returns the value of attribute batch.
Instance Method Summary collapse
- #<<(records) ⇒ Object
-
#initialize(batch) ⇒ Writer
constructor
A new instance of Writer.
- #save(records) ⇒ Object
Constructor Details
#initialize(batch) ⇒ Writer
Returns a new instance of Writer.
7 8 9 |
# File 'lib/origami-importer/writer.rb', line 7 def initialize(batch) self.batch = batch end |
Instance Attribute Details
#batch ⇒ Object
Returns the value of attribute batch.
6 7 8 |
# File 'lib/origami-importer/writer.rb', line 6 def batch @batch end |
Instance Method Details
#<<(records) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/origami-importer/writer.rb', line 11 def <<(records) records = [records].flatten.compact result = {} records.each do |record| key = record.keys.first value = record.values.first result[key] ||= [] result[key] << value end save result end |
#save(records) ⇒ Object
23 24 25 26 27 |
# File 'lib/origami-importer/writer.rb', line 23 def save(records) unless records.empty? batch.save records end end |