Class: Cukunity::Unity::JSONContainer

Inherits:
Object
  • Object
show all
Includes:
Cukunity::Utils
Defined in:
lib/cukunity/unity/json_container.rb

Direct Known Subclasses

Component, GameObject, Hint, Level, Scene, Screen

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cukunity::Utils

#check_timeout, #merge_options, #restrict_options, #to_options, #wait_connectivity

Constructor Details

#initialize(json) ⇒ JSONContainer

Returns a new instance of JSONContainer.



7
8
9
# File 'lib/cukunity/unity/json_container.rb', line 7

def initialize(json)
  @json = json
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object

inspect json structure dynamically



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cukunity/unity/json_container.rb', line 31

def method_missing(meth, *args, &block)
  if json.is_a? Hash
    meth = meth.to_s
    return property(meth) if has_property?(meth)
    if meth[-1..-1] == '?'
      meth = meth[0...-1]
      return !!property(meth) if has_property?(meth)
    end
  end
  super
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



5
6
7
# File 'lib/cukunity/unity/json_container.rb', line 5

def json
  @json
end

Instance Method Details

#has_key?(key) ⇒ Boolean Also known as: has_property?

Returns:

  • (Boolean)


24
25
26
# File 'lib/cukunity/unity/json_container.rb', line 24

def has_key?(key)
  @json.has_key?(key.to_s)
end

#keysObject Also known as: properties



18
19
20
# File 'lib/cukunity/unity/json_container.rb', line 18

def keys
  @json.keys
end

#to_sObject



43
44
45
# File 'lib/cukunity/unity/json_container.rb', line 43

def to_s
  @json.to_s
end

#value_of(key) ⇒ Object Also known as: [], property



11
12
13
# File 'lib/cukunity/unity/json_container.rb', line 11

def value_of(key)
  @json[key.to_s]
end