Class: JsonStructure::Object_

Inherits:
Type
  • Object
show all
Defined in:
lib/json_structure/object.rb

Instance Method Summary collapse

Methods inherited from Type

#|

Constructor Details

#initialize(hash = nil) ⇒ Object_

Returns a new instance of Object_.



3
4
5
6
7
# File 'lib/json_structure/object.rb', line 3

def initialize(hash = nil)
  @hash = hash && hash.each_with_object({}) do |(key, value), new_hash|
    new_hash[key.to_s] = value
  end
end

Instance Method Details

#===(value) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/json_structure/object.rb', line 9

def ===(value)
  return false unless value.is_a?(Hash)

  if @hash
    return @hash.all? do |key, type|
      type === value[key]
    end
  end

  true
end