Class: Yasd::Mapper
- Inherits:
-
Object
- Object
- Yasd::Mapper
- Defined in:
- lib/yasd/mapper.rb
Instance Method Summary collapse
- #call(data) ⇒ Object
-
#initialize(filepath) ⇒ Mapper
constructor
A new instance of Mapper.
Constructor Details
#initialize(filepath) ⇒ Mapper
Returns a new instance of Mapper.
5 6 7 |
# File 'lib/yasd/mapper.rb', line 5 def initialize(filepath) @mappings = filepath ? YAML.load_file(filepath) : {} end |
Instance Method Details
#call(data) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/yasd/mapper.rb', line 9 def call(data) data.each_with_object({}) do |(field, value), new_object| new_key = @mappings[field] || field new_object[new_key] = value new_object end end |