Class: Reading::CSV
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(feed = nil, path: nil, config: {}) ⇒ CSV
constructor
A new instance of CSV.
-
#parse ⇒ Array<Struct>
Parses a CSV reading log into item data (an array of Structs).
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
21 22 23 |
# File 'lib/reading/csv.rb', line 21 def config @config end |
Instance Method Details
#parse ⇒ Array<Struct>
Parses a CSV reading log into item data (an array of Structs). For what the Structs look like, see the Hash at @default_config[:template] in config.rb. The Structs are identical in structure to that Hash (with every inner Hash replaced with a Struct).
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/reading/csv.rb', line 41 def parse feed = @feed || File.open(@path) items = [] feed.each_line do |string| line = Line.new(string, self) row = line.to_row items += row.parse end items.map(&:to_struct) ensure feed&.close if feed.respond_to?(:close) end |