class Norma43::LineParsers::LineParser
Attributes
Public Class Methods
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
Source
# File lib/norma43/line_parsers/line_parser.rb, line 30 def self.field_names @field_names ||= [] end
Source
# File lib/norma43/line_parsers/line_parser.rb, line 7 def initialize(line) @line = line end
Public Instance Methods
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
Source
# File lib/norma43/line_parsers/line_parser.rb, line 38 def typecast(value, type) Norma43::Utils::Typecaster.cast value, type end
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