Class: Norma43::LineParsers::LineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/norma43/line_parsers/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.



7
8
9
# File 'lib/norma43/line_parsers/line_parser.rb', line 7

def initialize(line)
  @line = line
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



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

def line
  @line
end

Class Method Details

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



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

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

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

Instance Method Details

#attributesObject



11
12
13
14
15
# File 'lib/norma43/line_parsers/line_parser.rb', line 11

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