Class: VORuby::VOEvent::V1_1::Described

Inherits:
Base
  • Object
show all
Defined in:
lib/voruby/voevent/1.1/voevent.rb

Direct Known Subclasses

Citations, Group, How, Inference, VOEvent, What, WhereWhen, Who, Why

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(descriptions = nil, references = nil) ⇒ Described

Returns a new instance of Described.



162
163
164
165
# File 'lib/voruby/voevent/1.1/voevent.rb', line 162

def initialize(descriptions=nil, references=nil)
  self.descriptions = descriptions
  self.references = references
end

Instance Attribute Details

#descriptionsObject

Returns the value of attribute descriptions.



160
161
162
# File 'lib/voruby/voevent/1.1/voevent.rb', line 160

def descriptions
  @descriptions
end

#referencesObject

Returns the value of attribute references.



160
161
162
# File 'lib/voruby/voevent/1.1/voevent.rb', line 160

def references
  @references
end

Class Method Details

.described_from_xml(root) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/voruby/voevent/1.1/voevent.rb', line 200

def self.described_from_xml(root)
  descrs = REXML::XPath.match(root, 'x:Description', {'x' => obj_ns.uri})
  descrs = nil if descrs.size == 0
  
  refs = REXML::XPath.match(root, 'x:Reference', {'x' => obj_ns.uri})
  refs = nil if refs.size == 0
  
  [
    descrs ? DescriptionList.new(descrs.collect{ |d| Description.from_xml(d) }) : nil,
    refs ? ReferenceList.new(refs.collect{ |r| Reference.from_xml(r) }) : nil
  ]
end

.from_xml(xml) ⇒ Object



213
214
215
216
# File 'lib/voruby/voevent/1.1/voevent.rb', line 213

def self.from_xml(xml)
  root = element_from(xml)
  self.new(*described_from_xml(root))
end

Instance Method Details

#==(h) ⇒ Object



185
186
187
188
# File 'lib/voruby/voevent/1.1/voevent.rb', line 185

def ==(h)
  self.descriptions == h.descriptions and
  self.references == h.references
end

#to_xml(name = nil) ⇒ Object



190
191
192
193
194
195
196
197
198
# File 'lib/voruby/voevent/1.1/voevent.rb', line 190

def to_xml(name=nil)
  el = element(name)

  self.descriptions.each{ |d| el.add_element(d.to_xml('Description')) } if self.descriptions
  self.references.each{ |r| el.add_element(r.to_xml('Reference')) } if self.references

  collapse_namespaces(el)
  el
end