class Norma43::LineParsers::LineParser
Attributes
line[R]
Public Class Methods
field(name, range, type = :string)
click to toggle source
# 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
field_names()
click to toggle source
# File lib/norma43/line_parsers/line_parser.rb, line 30 def self.field_names @field_names ||= [] end
new(line)
click to toggle source
# File lib/norma43/line_parsers/line_parser.rb, line 7 def initialize(line) @line = line end
Public Instance Methods
attributes()
click to toggle source
# 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
Private Instance Methods
typecast(value, type)
click to toggle source
# File lib/norma43/line_parsers/line_parser.rb, line 38 def typecast(value, type) Norma43::Utils::Typecaster.cast value, type end
value_at_position(range, type)
click to toggle source
# File lib/norma43/line_parsers/line_parser.rb, line 34 def value_at_position(range, type) typecast line[range].to_s.strip, type end