Class: Attrocity::KeyMapper
- Inherits:
-
Object
- Object
- Attrocity::KeyMapper
- Defined in:
- lib/attrocity/mappers/key_mapper.rb
Instance Attribute Summary collapse
-
#default_value ⇒ Object
readonly
Returns the value of attribute default_value.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #call(_, attributes_data) ⇒ Object
-
#initialize(key, default_value = nil) ⇒ KeyMapper
constructor
A new instance of KeyMapper.
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_value ⇒ Object (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 |
#key ⇒ Object (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 |