Class: Materialist::Materializer::Internals::FieldMapping

Inherits:
Object
  • Object
show all
Defined in:
lib/materialist/materializer/internals/field_mapping.rb

Instance Method Summary collapse

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