class Headache::Record::Base
Public Class Methods
fields()
click to toggle source
# File lib/headache/record/base.rb, line 14 def self.fields @record_fields.to_a.map { |i| i.last }.inject({}) { |m,i| m[i[:name]] = i.except(:name); m } end
normalize_field_value(field, value)
click to toggle source
# File lib/headache/record/base.rb, line 18 def self.normalize_field_value(field, value) field_type = fields[field].try(:[],:type) return value if field_type.nil? case field_type when :numeric_value value.gsub(/^0+/,'').to_i when :alphanumeric value.strip when :nothing nil else value end end
parse_fields(record_string)
click to toggle source
# File lib/headache/record/base.rb, line 8 def self.parse_fields(record_string) parse(record_string)[:fields].inject({}) do |m,i| m[i[:name]] = i[:value]; m end end
parse_fields_normalize(record_string)
click to toggle source
# File lib/headache/record/base.rb, line 4 def self.parse_fields_normalize(record_string) parse_fields(record_string).inject({}) { |m,i| m[i.first] = normalize_field_value(i.first, i.last); m } end
Public Instance Methods
normalize_field_value(f, v)
click to toggle source
# File lib/headache/record/base.rb, line 34 def normalize_field_value(f, v) self.class.normalize_field_value(f, v) end
parse(record_string)
click to toggle source
# File lib/headache/record/base.rb, line 47 def parse(record_string) parse_fields(record_string).each_pair do |field, value| if respond_to?("#{field}=") send "#{field}=", normalize_field_value(field, value) end end self end
parse_fields(record_string)
click to toggle source
# File lib/headache/record/base.rb, line 43 def parse_fields(record_string) self.class.parse_fields record_string end
to_h()
click to toggle source
# File lib/headache/record/base.rb, line 38 def to_h str = self.generate.gsub Headache::DocumentParser::LINE_SEPARATOR, '' self.class.parse_fields(str) end