Class: Plumb::HashMap::FilteredHashMap
- Inherits:
-
Object
- Object
- Plumb::HashMap::FilteredHashMap
- Includes:
- Steppable
- Defined in:
- lib/plumb/hash_map.rb
Instance Attribute Summary collapse
-
#key_type ⇒ Object
readonly
Returns the value of attribute key_type.
-
#value_type ⇒ Object
readonly
Returns the value of attribute value_type.
Attributes included from Steppable
Instance Method Summary collapse
- #call(result) ⇒ Object
-
#initialize(key_type, value_type) ⇒ FilteredHashMap
constructor
A new instance of FilteredHashMap.
Methods included from Steppable
#===, #>>, #[], #as_node, #build, #check, #defer, #freeze, included, #inspect, #invalid, #invoke, #match, #meta, #node_name, #not, #pipeline, #policy, #to_s, #transform, #value, wrap, #|
Methods included from Callable
Constructor Details
#initialize(key_type, value_type) ⇒ FilteredHashMap
Returns a new instance of FilteredHashMap.
48 49 50 51 52 |
# File 'lib/plumb/hash_map.rb', line 48 def initialize(key_type, value_type) @key_type = key_type @value_type = value_type freeze end |
Instance Attribute Details
#key_type ⇒ Object (readonly)
Returns the value of attribute key_type.
46 47 48 |
# File 'lib/plumb/hash_map.rb', line 46 def key_type @key_type end |
#value_type ⇒ Object (readonly)
Returns the value of attribute value_type.
46 47 48 |
# File 'lib/plumb/hash_map.rb', line 46 def value_type @value_type end |
Instance Method Details
#call(result) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/plumb/hash_map.rb', line 54 def call(result) result.invalid(errors: 'must be a Hash') unless result.value.is_a?(::Hash) hash = result.value.each.with_object({}) do |(key, value), memo| key_r = @key_type.resolve(key) value_r = @value_type.resolve(value) memo[key_r.value] = value_r.value if key_r.valid? && value_r.valid? end result.valid(hash) end |