Class: NRSER::Types::HashType

Inherits:
IsA
  • Object
show all
Defined in:
lib/nrser/types/hashes.rb

Instance Attribute Summary collapse

Attributes inherited from IsA

#klass

Instance Method Summary collapse

Methods inherited from IsA

#default_name, #from_data, #has_from_data?

Methods inherited from Type

#check, #default_name, #from_data, #from_s, #has_from_data?, #has_from_s?, #has_to_data?, #name, #respond_to?, short_name, #to_data, #to_s

Constructor Details

#initialize(keys: NRSER::Types::ANY, values: NRSER::Types::ANY, **options) ⇒ HashType

Returns a new instance of HashType.



11
12
13
14
15
16
17
18
# File 'lib/nrser/types/hashes.rb', line 11

def initialize  keys: NRSER::Types::ANY,
                values: NRSER::Types::ANY,
                **options
  super ::Hash, **options
  
  @keys = NRSER::Types.make keys
  @values = NRSER::Types.make values
end

Instance Attribute Details

#keysObject (readonly)

, :including, :exactly, :min, :max



9
10
11
# File 'lib/nrser/types/hashes.rb', line 9

def keys
  @keys
end

#valuesObject (readonly)

, :including, :exactly, :min, :max



9
10
11
# File 'lib/nrser/types/hashes.rb', line 9

def values
  @values
end

Instance Method Details

#test(value) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nrser/types/hashes.rb', line 20

def test value
  return false unless super(value)
  
  if keys == NRSER::Types::ANY && values == NRSER::Types::ANY
    return true
  end
  
  value.all? { |k, v|
    keys.test(k) && values.test(v)
  }
end