Class: ETL::Parser::DelimitedParser
- Defined in:
- lib/etl/parser/delimited_parser.rb
Overview
Parses delimited files
Defined Under Namespace
Classes: Field
Instance Attribute Summary
Attributes inherited from Parser
Instance Method Summary collapse
-
#each ⇒ Object
Returns each row.
-
#fields ⇒ Object
Get an array of defined fields.
-
#initialize(source, options = {}) ⇒ DelimitedParser
constructor
Initialize the parser *
source
: The Source object *options
: Hash of options for the parser, defaults to an empty hash.
Methods inherited from Parser
Constructor Details
#initialize(source, options = {}) ⇒ DelimitedParser
Initialize the parser
-
source
: The Source object -
options
: Hash of options for the parser, defaults to an empty hash
8 9 10 11 |
# File 'lib/etl/parser/delimited_parser.rb', line 8 def initialize(source, ={}) super configure end |
Instance Method Details
#each ⇒ Object
Returns each row.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/etl/parser/delimited_parser.rb', line 14 def each Dir.glob(file).each do |file| ETL::Engine.logger.debug "parsing #{file}" line = 0 lines_skipped = 0 FasterCSV.foreach(file, ) do |raw_row| if lines_skipped < source.skip_lines ETL::Engine.logger.debug "skipping line" lines_skipped += 1 next end line += 1 row = {} validate_row(raw_row, line, file) raw_row.each_with_index do |value, index| f = fields[index] row[f.name] = value end yield row end end end |
#fields ⇒ Object
Get an array of defined fields
38 39 40 |
# File 'lib/etl/parser/delimited_parser.rb', line 38 def fields @fields ||= [] end |