Class: HappyMapper::SupportedTypes::CastWhenType
- Inherits:
-
Object
- Object
- HappyMapper::SupportedTypes::CastWhenType
- Defined in:
- lib/happymapper/supported_types.rb
Overview
Many of the conversions are based on type. When the type specified matches then perform the action specified in the specified block. If no block is provided the value is simply returned.
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #apply(value) ⇒ Object
- #apply?(value, convert_to_type) ⇒ Boolean
-
#initialize(type, &block) ⇒ CastWhenType
constructor
A new instance of CastWhenType.
- #no_operation ⇒ Object
Constructor Details
#initialize(type, &block) ⇒ CastWhenType
Returns a new instance of CastWhenType.
60 61 62 63 |
# File 'lib/happymapper/supported_types.rb', line 60 def initialize(type,&block) @type = type @apply_block = block || no_operation end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
58 59 60 |
# File 'lib/happymapper/supported_types.rb', line 58 def type @type end |
Instance Method Details
#apply(value) ⇒ Object
73 74 75 |
# File 'lib/happymapper/supported_types.rb', line 73 def apply(value) @apply_block.call(value) end |
#apply?(value, convert_to_type) ⇒ Boolean
69 70 71 |
# File 'lib/happymapper/supported_types.rb', line 69 def apply?(value,convert_to_type) convert_to_type == type end |
#no_operation ⇒ Object
65 66 67 |
# File 'lib/happymapper/supported_types.rb', line 65 def no_operation lambda {|value| value } end |