Class: TotalIn::LineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/total_in/line_parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ LineParser

Returns a new instance of LineParser.



6
7
8
# File 'lib/total_in/line_parser.rb', line 6

def initialize line
  @line = line
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



5
6
7
# File 'lib/total_in/line_parser.rb', line 5

def line
  @line
end

Class Method Details

.field(name, range, type = :string) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/total_in/line_parser.rb', line 16

def self.field name, range, type = :string
  self.field_names.push name

  define_method name do
    if range.is_a?(Array)
      range.map { |r| value_at_position(r, type) }.compact
    else
      value_at_position range, type
    end
  end
end

Instance Method Details

#attributesObject



10
11
12
13
14
# File 'lib/total_in/line_parser.rb', line 10

def attributes
  self.class.field_names.each_with_object({}) do |field, attrs|
    attrs[field] = self.public_send(field)
  end
end