Class: ROM::CSV::Dataset

Inherits:
Memory::Dataset
  • Object
show all
Defined in:
lib/rom/csv/dataset.rb

Overview

Dataset for CSV

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.row_procObject

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

#countObject



39
40
41
# File 'lib/rom/csv/dataset.rb', line 39

def count
  data.count
end

#load_dataObject



35
36
37
# File 'lib/rom/csv/dataset.rb', line 35

def load_data
  ::CSV.table(path, file_options).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_dataObject



27
28
29
30
31
32
33
# File 'lib/rom/csv/dataset.rb', line 27

def write_data
  ::CSV.open(path, 'wb', file_options) do |csv|
    data.to_a.each do |tuple|
      csv << tuple
    end
  end
end