Class: Extant::Coercers::Hash
Constant Summary
Constants inherited from Base
Class Attribute Summary collapse
-
.key_type ⇒ Object
Returns the value of attribute key_type.
-
.value_type ⇒ Object
Returns the value of attribute value_type.
Instance Method Summary collapse
Methods inherited from Base
#coerced?, coercer_name, #initialize
Constructor Details
This class inherits a constructor from Extant::Coercers::Base
Class Attribute Details
.key_type ⇒ Object
Returns the value of attribute key_type.
4 5 6 |
# File 'lib/extant/coercers/hash.rb', line 4 def key_type @key_type end |
.value_type ⇒ Object
Returns the value of attribute value_type.
4 5 6 |
# File 'lib/extant/coercers/hash.rb', line 4 def value_type @value_type end |
Instance Method Details
#coerce ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/extant/coercers/hash.rb', line 7 def coerce result = ::Hash[value] if key_type && value_type result = result.each_with_object({}) do |(k, v), h| h[coerce_key(k)] = coerce_value(v) end end self.coerced = true result rescue ArgumentError UncoercedValue end |