Class: Format::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/src/format/mapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(yml) ⇒ Mapper

Returns a new instance of Mapper.



5
6
7
# File 'lib/src/format/mapper.rb', line 5

def initialize(yml)
  @mappers = yml.fetch(:mappers, {})
end

Instance Method Details

#apply(raw_value, mapper_name) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/src/format/mapper.rb', line 9

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