Class: Materialist::Materializer::Internals::FieldMapping
- Inherits:
-
Object
- Object
- Materialist::Materializer::Internals::FieldMapping
- Defined in:
- lib/materialist/materializer/internals/field_mapping.rb
Instance Method Summary collapse
-
#initialize(key:, as: key, value_parser: nil) ⇒ FieldMapping
constructor
A new instance of FieldMapping.
- #map(resource) ⇒ Object
Constructor Details
#initialize(key:, as: key, value_parser: nil) ⇒ FieldMapping
Returns a new instance of FieldMapping.
5 6 7 8 9 |
# File 'lib/materialist/materializer/internals/field_mapping.rb', line 5 def initialize(key:, as: key, value_parser: nil) @key = key @as = as @value_parser = value_parser || ->value { value } end |
Instance Method Details
#map(resource) ⇒ Object
11 12 13 |
# File 'lib/materialist/materializer/internals/field_mapping.rb', line 11 def map(resource) { @as => @value_parser.call(resource.dig(@key)) } end |