Class: FixedWidth::Parser

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

Instance Method Summary collapse

Constructor Details

#initialize(definition, file) ⇒ Parser

Returns a new instance of Parser.



3
4
5
6
# File 'lib/fixed_width/parser.rb', line 3

def initialize(definition, file)
  @definition = definition
  @file       = file
end

Instance Method Details

#parseObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fixed_width/parser.rb', line 8

def parse
  @parsed = {}
  @content = read_file
  unless @content.empty?
    @definition.sections.each do |section|
      rows = fill_content(section)
      raise FixedWidth::RequiredSectionNotFoundError.new("Required section '#{section.name}' was not found.") unless rows > 0 || section.optional
    end
  end
  @parsed
end