class Yarrow::Schema::Types::Map
Attributes
key_type[R]
Public Class Methods
new(key_type, value_type)
click to toggle source
Calls superclass method
Yarrow::Schema::Types::TypeClass::new
# File lib/yarrow/schema/types.rb, line 196 def initialize(key_type, value_type) @key_type = key_type super(value_type) end
of(map_spec)
click to toggle source
# File lib/yarrow/schema/types.rb, line 178 def self.of(map_spec) if map_spec.is_a?(Hash) if map_spec.size == 1 key_type, value_type = map_spec.first else raise "map requires a single key => value type" end else key_type = Symbol value_type = map_spec end new(Instance.of(key_type), Instance.of(value_type)) end
Public Instance Methods
check(input)
click to toggle source
# File lib/yarrow/schema/types.rb, line 201 def check(input) keys = input.keys.map do |key| key_type.cast(key) end values = input.values.map do |value| value_type.cast(value) end [keys, values].transpose.to_h end