Class: SiriObject
- Inherits:
-
Object
- Object
- SiriObject
- Defined in:
- lib/siri_objects.rb
Direct Known Subclasses
SiriAddViews, SiriAnswer, SiriAnswerLine, SiriAnswerSnippet, SiriAssistantUtteranceView, SiriButton, SiriCancelSnippetCommand, SiriConfirmSnippetCommand, SiriConfirmationOptions, SiriGetRequestOrigin, SiriLocation, SiriMapItem, SiriMapItemSnippet, SiriRequestCompleted, SiriSendCommands, SiriSetRequestOrigin, SiriStartRequest
Instance Attribute Summary collapse
-
#group ⇒ Object
Returns the value of attribute group.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#properties ⇒ Object
Returns the value of attribute properties.
Instance Method Summary collapse
-
#initialize(klass, group) ⇒ SiriObject
constructor
A new instance of SiriObject.
- #make_root(ref_id = nil, ace_id = nil) ⇒ Object
-
#to_hash ⇒ Object
watch out for circular references!.
Constructor Details
#initialize(klass, group) ⇒ SiriObject
Returns a new instance of SiriObject.
21 22 23 24 25 |
# File 'lib/siri_objects.rb', line 21 def initialize(klass, group) @klass = klass @group = group @properties = {} end |
Instance Attribute Details
#group ⇒ Object
Returns the value of attribute group.
19 20 21 |
# File 'lib/siri_objects.rb', line 19 def group @group end |
#klass ⇒ Object
Returns the value of attribute klass.
19 20 21 |
# File 'lib/siri_objects.rb', line 19 def klass @klass end |
#properties ⇒ Object
Returns the value of attribute properties.
19 20 21 |
# File 'lib/siri_objects.rb', line 19 def properties @properties end |
Instance Method Details
#make_root(ref_id = nil, ace_id = nil) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/siri_objects.rb', line 50 def make_root(ref_id=nil, ace_id=nil) self.extend(SiriRootObject) self.ref_id = (ref_id || random_ref_id) self.ace_id = (ace_id || random_ace_id) end |
#to_hash ⇒ Object
watch out for circular references!
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/siri_objects.rb', line 28 def to_hash hash = { "class" => self.klass, "group" => self.group, "properties" => {} } (hash["refId"] = ref_id) rescue nil (hash["aceId"] = ace_id) rescue nil properties.each_key { |key| if properties[key].class == Array hash["properties"][key] = [] self.properties[key].each { |val| hash["properties"][key] << (val.to_hash rescue val) } else hash["properties"][key] = (properties[key].to_hash rescue properties[key]) end } hash end |