class HappyMapper::SupportedTypes::CastWhenType
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.
Attributes
type[R]
Public Class Methods
new(type, &block)
click to toggle source
# File lib/happymapper/supported_types.rb, line 62 def initialize(type, &block) @type = type @apply_block = block || no_operation end
Public Instance Methods
apply(value)
click to toggle source
# File lib/happymapper/supported_types.rb, line 75 def apply(value) @apply_block.call(value) end
apply?(_value, convert_to_type)
click to toggle source
# File lib/happymapper/supported_types.rb, line 71 def apply?(_value, convert_to_type) convert_to_type == type end
no_operation()
click to toggle source
# File lib/happymapper/supported_types.rb, line 67 def no_operation ->(value) { value } end