Class: Strict::Coercers::Hash
- Inherits:
-
Object
- Object
- Strict::Coercers::Hash
- Defined in:
- lib/strict/coercers/hash.rb
Instance Attribute Summary collapse
-
#key_coercer ⇒ Object
readonly
Returns the value of attribute key_coercer.
-
#value_coercer ⇒ Object
readonly
Returns the value of attribute value_coercer.
Instance Method Summary collapse
- #call(value) ⇒ Object
-
#initialize(key_coercer = nil, value_coercer = nil) ⇒ Hash
constructor
A new instance of Hash.
Constructor Details
#initialize(key_coercer = nil, value_coercer = nil) ⇒ Hash
Returns a new instance of Hash.
8 9 10 11 |
# File 'lib/strict/coercers/hash.rb', line 8 def initialize(key_coercer = nil, value_coercer = nil) @key_coercer = key_coercer @value_coercer = value_coercer end |
Instance Attribute Details
#key_coercer ⇒ Object (readonly)
Returns the value of attribute key_coercer.
6 7 8 |
# File 'lib/strict/coercers/hash.rb', line 6 def key_coercer @key_coercer end |
#value_coercer ⇒ Object (readonly)
Returns the value of attribute value_coercer.
6 7 8 |
# File 'lib/strict/coercers/hash.rb', line 6 def value_coercer @value_coercer end |
Instance Method Details
#call(value) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/strict/coercers/hash.rb', line 13 def call(value) return value if value.nil? || !value.respond_to?(:to_h) if key_coercer && value_coercer coerce_keys_and_values(value.to_h) elsif key_coercer coerce_keys(value.to_h) elsif value_coercer coerce_values(value.to_h) else value.to_h end end |