Sha256: f84e3ea3d3452795841bf2696167b3bd4c92ab0c6756bd34ba3632ef4da07812
Contents?: true
Size: 844 Bytes
Versions: 2
Compression:
Stored size: 844 Bytes
Contents
module DataForge module File module CSV class CSVRecordFileReader attr_reader :definition, :name, :fields def initialize(definition) @definition = definition @name = definition.name @fields = definition.field_names end def each_record(&block) ::CSV.open definition.file_name, csv_options 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 private def csv_options {col_sep: definition.delimiter, quote_char: definition.quote, encoding: definition.encoding, return_headers: false} end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
data_forge-0.1.1 | lib/data_forge/file/csv/csv_record_file_reader.rb |
data_forge-0.1 | lib/data_forge/file/csv/csv_record_file_reader.rb |