class Format::Mapper
Attributes
mappers[R]
Public Class Methods
new(yml)
click to toggle source
# File lib/src/format/mapper.rb, line 3 def initialize(yml) @mappers = yml.fetch(:mappers, {}) end
Public Instance Methods
apply(raw_value, mapper_name)
click to toggle source
# File lib/src/format/mapper.rb, line 7 def apply(raw_value, mapper_name) return raw_value unless mapper_name mappers.each do |name, fields| return mapper_value(fields, raw_value) if mapper_name.to_sym == name end raise "Mapper not found #{mapper_name}" end
Private Instance Methods
mapper_value(fields, value)
click to toggle source
# File lib/src/format/mapper.rb, line 21 def mapper_value(fields, value) (fields[:options] || []).each do |option, values| return option.to_s if [values].flatten.include?(value.to_s) end fields[:default] || value end