Class: Sumac::Message::Object::Array
- Inherits:
-
Base
show all
- Defined in:
- lib/sumac/message/object/array.rb
Instance Method Summary
collapse
Methods inherited from Base
from_json_structure, from_native_object
from_json_structure, from_native_object
from_json, #to_json
Constructor Details
#initialize(connection) ⇒ Array
Returns a new instance of Array.
6
7
8
9
|
# File 'lib/sumac/message/object/array.rb', line 6
def initialize(connection)
super
@elements = nil
end
|
Instance Method Details
#invert_orgin ⇒ Object
42
43
44
45
46
|
# File 'lib/sumac/message/object/array.rb', line 42
def invert_orgin
raise MessageError unless setup?
@elements.each { |element| element.invert_orgin if element.respond_to?(:invert_orgin) }
nil
end
|
#parse_json_structure(json_structure) ⇒ Object
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/sumac/message/object/array.rb', line 11
def parse_json_structure(json_structure)
raise MessageError unless json_structure.is_a?(::Hash) &&
json_structure['message_type'] == 'object' &&
json_structure['object_type'] == 'array'
raise MessageError unless json_structure['elements'].is_a?(::Array)
@elements = json_structure['elements'].map do |element|
Object.from_json_structure(@connection, element)
end
nil
end
|
#parse_native_object(native_object) ⇒ Object
22
23
24
25
26
|
# File 'lib/sumac/message/object/array.rb', line 22
def parse_native_object(native_object)
raise MessageError unless native_object.is_a?(::Array)
@elements = native_object.map { |element| Object.from_native_object(@connection, element) }
nil
end
|
#to_json_structure ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/sumac/message/object/array.rb', line 28
def to_json_structure
raise MessageError unless setup?
{
'message_type' => 'object',
'object_type' => 'array',
'elements' => @elements.map(&:to_json_structure)
}
end
|
#to_native_object ⇒ Object
37
38
39
40
|
# File 'lib/sumac/message/object/array.rb', line 37
def to_native_object
raise MessageError unless setup?
@elements.map(&:to_native_object)
end
|