Class: Sumac::Message::Object::String

Inherits:
Base show all
Defined in:
lib/sumac/message/object/string.rb

Instance Method Summary collapse

Methods inherited from Base

from_json_structure, from_native_object

Methods inherited from Sumac::Message::Object

from_json_structure, from_native_object

Methods inherited from Sumac::Message

from_json, #to_json

Constructor Details

#initialize(connection) ⇒ String

Returns a new instance of String.



6
7
8
9
# File 'lib/sumac/message/object/string.rb', line 6

def initialize(connection)
  super
  @value = nil
end

Instance Method Details

#parse_json_structure(json_structure) ⇒ Object

Raises:



11
12
13
14
15
16
17
18
# File 'lib/sumac/message/object/string.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'] == 'string'
  raise MessageError unless json_structure['value'].is_a?(::String)
  @value = json_structure['value']
  nil
end

#parse_native_object(native_object) ⇒ Object

Raises:



20
21
22
23
24
# File 'lib/sumac/message/object/string.rb', line 20

def parse_native_object(native_object)
  raise MessageError unless native_object.is_a?(::String)
  @value = native_object
  nil
end

#to_json_structureObject

Raises:



26
27
28
29
# File 'lib/sumac/message/object/string.rb', line 26

def to_json_structure
  raise MessageError unless setup?
  {'message_type' => 'object', 'object_type' => 'string', 'value' => @value}
end

#to_native_objectObject

Raises:



31
32
33
34
# File 'lib/sumac/message/object/string.rb', line 31

def to_native_object
  raise MessageError unless setup?
  @value
end