Class: Estratto::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, layout) ⇒ Parser

Returns a new instance of Parser.



8
9
10
11
# File 'lib/estratto/parser.rb', line 8

def initialize(file_path, layout)
  @file_path = file_path
  @layout = layout
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



6
7
8
# File 'lib/estratto/parser.rb', line 6

def file_path
  @file_path
end

#layoutObject (readonly)

Returns the value of attribute layout.



6
7
8
# File 'lib/estratto/parser.rb', line 6

def layout
  @layout
end

Instance Method Details

#performObject



13
14
15
16
17
18
19
# File 'lib/estratto/parser.rb', line 13

def perform
  @data ||= raw_content.map do |line|
    register_layout = layout.register_fields_for(line[layout.prefix_range])
    next if register_layout.nil?
    Register.new(line, register_layout).refine
  end.compact
end

#raw_contentObject



21
22
23
# File 'lib/estratto/parser.rb', line 21

def raw_content
  @raw_data = Content.for(file_path)
end