Class: SiriObject

Inherits:
Object
  • Object
show all
Defined in:
lib/siri_objects.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#groupObject

Returns the value of attribute group.



19
20
21
# File 'lib/siri_objects.rb', line 19

def group
  @group
end

#klassObject

Returns the value of attribute klass.



19
20
21
# File 'lib/siri_objects.rb', line 19

def klass
  @klass
end

#propertiesObject

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_hashObject

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