Class: ArcFurnace::CSVSource
- Includes:
- CSVToHashWithDuplicateHeaders
- Defined in:
- lib/arc-furnace/csv_source.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Node
#error_handler, #node_id, #params
Instance Method Summary collapse
- #advance ⇒ Object
-
#empty? ⇒ Boolean
Is this source empty?.
-
#initialize(filename:, encoding: 'UTF-8') ⇒ CSVSource
constructor
A new instance of CSVSource.
Methods included from CSVToHashWithDuplicateHeaders
Methods inherited from Source
#close, #finalize, #prepare, #row
Constructor Details
#initialize(filename:, encoding: 'UTF-8') ⇒ CSVSource
Returns a new instance of CSVSource.
11 12 13 14 15 |
# File 'lib/arc-furnace/csv_source.rb', line 11 def initialize(filename: , encoding: 'UTF-8') @file = File.open(filename, encoding: encoding) @csv = CSV.new(file, encoding: encoding, headers: true).each advance end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
9 10 11 |
# File 'lib/arc-furnace/csv_source.rb', line 9 def file @file end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
9 10 11 |
# File 'lib/arc-furnace/csv_source.rb', line 9 def value @value end |
Instance Method Details
#advance ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/arc-furnace/csv_source.rb', line 22 def advance @value = begin csv_to_hash_with_duplicates(csv.next) if csv rescue StopIteration file.close @csv = nil nil end end |
#empty? ⇒ Boolean
Is this source empty?
18 19 20 |
# File 'lib/arc-furnace/csv_source.rb', line 18 def empty? !value end |