Class: SimpleEtl::Source::FixedWidth::Parser

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_etl/source/fixed_width/parser.rb

Instance Attribute Summary

Attributes inherited from Base

#context, #errors

Instance Method Summary collapse

Methods inherited from Base

#generate_field, #parse, #parse_field, #parse_row

Constructor Details

#initialize(&block) ⇒ Parser

Returns a new instance of Parser.



5
6
7
# File 'lib/simple_etl/source/fixed_width/parser.rb', line 5

def initialize &block
  super Context.new, &block
end

Instance Method Details

#fetch_field_from_row(row, field) ⇒ Object



9
10
11
12
13
# File 'lib/simple_etl/source/fixed_width/parser.rb', line 9

def fetch_field_from_row row, field
  length = field[:length]
  length = row.length - field[:start] if length == :eol
  row[field[:start], length]
end

#read_rows(src, args) ⇒ Object



15
16
17
# File 'lib/simple_etl/source/fixed_width/parser.rb', line 15

def read_rows src, args
  (args[:type] == :inline && src.lines || File.readlines(src)).map &:chomp
end