Class: ROM::CSV::Dataset
- Inherits:
-
Memory::Dataset
- Object
- Memory::Dataset
- ROM::CSV::Dataset
- Defined in:
- lib/rom/csv/dataset.rb
Overview
Dataset for CSV
Class Method Summary collapse
-
.row_proc ⇒ Object
Convert each CSV::Row to a hash.
Instance Method Summary collapse
Class Method Details
.row_proc ⇒ Object
Convert each CSV::Row to a hash
15 16 17 |
# File 'lib/rom/csv/dataset.rb', line 15 def self.row_proc -> row { row.to_hash } end |
Instance Method Details
#count ⇒ Object
39 40 41 |
# File 'lib/rom/csv/dataset.rb', line 39 def count data.count end |
#load_data ⇒ Object
35 36 37 |
# File 'lib/rom/csv/dataset.rb', line 35 def load_data ::CSV.table(path, ).by_row! end |
#reload! ⇒ Object
19 20 21 |
# File 'lib/rom/csv/dataset.rb', line 19 def reload! @data = load_data end |
#sync! ⇒ Object
23 24 25 |
# File 'lib/rom/csv/dataset.rb', line 23 def sync! write_data && reload! end |
#write_data ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/rom/csv/dataset.rb', line 27 def write_data ::CSV.open(path, 'wb', ) do |csv| data.to_a.each do |tuple| csv << tuple end end end |