Module: IMW::Resources::Formats::Delimited Abstract
Overview
Defines methods used for parsing and writing delimited data formats (CSV, TSV, &c.) with the FasterCSV library. This module is not used to directly extend a resource. Instead, more specific modules (e.g. - IMW::Resources::Formats::Csv) include this one and also define delimited_options
which is actually what’s passed to FasterCSV.
Instance Attribute Summary collapse
-
#delimited_settings ⇒ Object
Returns the value of attribute delimited_settings.
Instance Method Summary collapse
-
#dump(data, options = {}) ⇒ Object
Dump an array of arrays into this resource.
-
#load {|Array| ... } ⇒ Array
Return the data in this delimited resource as an array of arrays.
-
#map {|Array| ... } ⇒ Object
Map each row in this delimited resource.
Instance Attribute Details
#delimited_settings ⇒ Object
Returns the value of attribute delimited_settings.
15 16 17 |
# File 'lib/imw/resources/formats/delimited.rb', line 15 def delimited_settings @delimited_settings end |
Instance Method Details
#dump(data, options = {}) ⇒ Object
Dump an array of arrays into this resource.
41 42 43 44 45 46 47 48 |
# File 'lib/imw/resources/formats/delimited.rb', line 41 def dump data, ={} require 'fastercsv' data.each do |row| write(FasterCSV.generate_line(row, )) end io.close unless [:persist] self end |
#load {|Array| ... } ⇒ Array
Return the data in this delimited resource as an array of arrays.
Yield each outer array (row) if passed a block.
24 25 26 27 |
# File 'lib/imw/resources/formats/delimited.rb', line 24 def load &block require 'fastercsv' FasterCSV.parse(read, , &block) end |
#map {|Array| ... } ⇒ Object
Map each row in this delimited resource.
32 33 34 |
# File 'lib/imw/resources/formats/delimited.rb', line 32 def map &block load.map(&block) end |