Module: IMW::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.
14 15 16 |
# File 'lib/imw/formats/delimited.rb', line 14 def delimited_settings @delimited_settings end |
Instance Method Details
#dump(data, options = {}) ⇒ Object
Dump an array of arrays into this resource.
40 41 42 43 44 45 46 47 |
# File 'lib/imw/formats/delimited.rb', line 40 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.
23 24 25 26 |
# File 'lib/imw/formats/delimited.rb', line 23 def load &block require 'fastercsv' FasterCSV.parse(read, , &block) end |
#map {|Array| ... } ⇒ Object
Map each row in this delimited resource.
31 32 33 |
# File 'lib/imw/formats/delimited.rb', line 31 def map &block load.map(&block) end |