Class: Attrocity::KeyMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/attrocity/mappers/key_mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, default_value = nil) ⇒ KeyMapper

Returns a new instance of KeyMapper.



5
6
7
8
# File 'lib/attrocity/mappers/key_mapper.rb', line 5

def initialize(key, default_value=nil)
  @key = key
  @default_value = default_value
end

Instance Attribute Details

#default_valueObject (readonly)

Returns the value of attribute default_value.



3
4
5
# File 'lib/attrocity/mappers/key_mapper.rb', line 3

def default_value
  @default_value
end

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/attrocity/mappers/key_mapper.rb', line 3

def key
  @key
end

Instance Method Details

#call(_, attributes_data) ⇒ Object



10
11
12
# File 'lib/attrocity/mappers/key_mapper.rb', line 10

def call(_, attributes_data)
  attributes_data.fetch(key, default_value)
end