Class: Zona::JSONElement

Inherits:
Object
  • Object
show all
Defined in:
zona/OZonesJSON.rb

Overview

This class represents an element described by a JSON string In practice, this is represented by a hash, result of parsing the JSON string.

Direct Known Subclasses

JSONPool, OZonesElement

Instance Method Summary (collapse)

Constructor Details

- (JSONElement) initialize(json_hash = nil)

Initializes an instance

Parameters:

  • json_hash (Hash) (defaults to: nil)

    a hash with the object description



73
74
75
# File 'zona/OZonesJSON.rb', line 73

def initialize(json_hash=nil)
    @json_hash=json_hash
end

Instance Method Details

- (String) [](key)

Accesses the value of a JSON element key

Parameters:

  • key (#to_sym)

Returns:

  • (String)

    Value



92
93
94
# File 'zona/OZonesJSON.rb', line 92

def [](key)
    @json_hash[key.to_sym]
end

- (Object) initialize_json(json_str, root_element)

Initializes an instance with a JSON description

Parameters:

  • json_str (String)

    JSON description

  • root_element (#to_sym)

    root element in the element description



80
81
82
83
84
85
86
87
# File 'zona/OZonesJSON.rb', line 80

def initialize_json(json_str, root_element)
    rc = OZonesJSON.build_json(json_str,root_element)
    @json_hash = rc

    if Zona.is_error?(rc) || (rc.size == 0)
        @json_hash=nil
    end
end