Class: DataForge::File::CSV::CSVRecordFileReader
- Inherits:
-
Object
- Object
- DataForge::File::CSV::CSVRecordFileReader
- Defined in:
- lib/data_forge/file/csv/csv_record_file_reader.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #each_record(&block) ⇒ Object
-
#initialize(definition) ⇒ CSVRecordFileReader
constructor
A new instance of CSVRecordFileReader.
Constructor Details
#initialize(definition) ⇒ CSVRecordFileReader
Returns a new instance of CSVRecordFileReader.
10 11 12 13 14 |
# File 'lib/data_forge/file/csv/csv_record_file_reader.rb', line 10 def initialize(definition) @definition = definition @name = definition.name @fields = definition.field_names end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
6 7 8 |
# File 'lib/data_forge/file/csv/csv_record_file_reader.rb', line 6 def definition @definition end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
6 7 8 |
# File 'lib/data_forge/file/csv/csv_record_file_reader.rb', line 6 def fields @fields end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/data_forge/file/csv/csv_record_file_reader.rb', line 6 def name @name end |
Instance Method Details
#each_record(&block) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/data_forge/file/csv/csv_record_file_reader.rb', line 18 def each_record(&block) ::CSV.open definition.file_name, do |csv_file| csv_file.shift if definition.has_header_row until (row = csv_file.shift).nil? block.call Hash[definition.field_names.zip row] end end end |