Class: VORuby::VOEvent::V1_1::Inference

Inherits:
Described show all
Defined in:
lib/voruby/voevent/1.1/voevent.rb

Instance Attribute Summary collapse

Attributes inherited from Described

#descriptions, #references

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Described

described_from_xml

Methods included from SerializableToXml

#element

Constructor Details

#initialize(names, concepts, probability = nil, relation = nil, descriptions = nil, references = nil) ⇒ Inference

Returns a new instance of Inference.



280
281
282
283
284
285
286
# File 'lib/voruby/voevent/1.1/voevent.rb', line 280

def initialize(names, concepts, probability=nil, relation=nil, descriptions=nil, references=nil)
  super(descriptions, references)
  self.names = names
  self.concepts = concepts
  self.probability = probability
  self.relation = relation
end

Instance Attribute Details

#conceptsObject

Returns the value of attribute concepts.



278
279
280
# File 'lib/voruby/voevent/1.1/voevent.rb', line 278

def concepts
  @concepts
end

#namesObject

Returns the value of attribute names.



278
279
280
# File 'lib/voruby/voevent/1.1/voevent.rb', line 278

def names
  @names
end

#probabilityObject

Returns the value of attribute probability.



278
279
280
# File 'lib/voruby/voevent/1.1/voevent.rb', line 278

def probability
  @probability
end

#relationObject

Returns the value of attribute relation.



278
279
280
# File 'lib/voruby/voevent/1.1/voevent.rb', line 278

def relation
  @relation
end

Class Method Details

.from_xml(xml) ⇒ Object



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/voruby/voevent/1.1/voevent.rb', line 348

def self.from_xml(xml)
  root = element_from(xml)
  
  names = REXML::XPath.match(root, 'x:Name', {'x' => obj_ns.uri})
  names = nil if names.size == 0
  
  concepts = REXML::XPath.match(root, 'x:Concept', {'x' => obj_ns.uri})
  concepts = nil if concepts.size == 0
  
  probability = root.attributes.get_attribute_ns(obj_ns.uri, 'probability')
  relation = root.attributes.get_attribute_ns(obj_ns.uri, 'relation')
  
  self.new(
    names ? NameList.new(names.collect{ |name| name.text }) : nil,
    concepts ? ConceptList.new(concepts.collect{ |concept| concept.text }) : nil,
    probability ? Float(probability.value) : nil,
    relation ? relation.value : nil,
    *Described.described_from_xml(root)
  )
end

Instance Method Details

#==(i) ⇒ Object



319
320
321
322
323
324
325
# File 'lib/voruby/voevent/1.1/voevent.rb', line 319

def ==(i)
  super(i) and
  self.names == i.names and
  self.concepts == i.concepts and
  self.probability == i.probability and
  self.relation == i.relation
end

#to_xml(name = nil) ⇒ Object



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/voruby/voevent/1.1/voevent.rb', line 327

def to_xml(name=nil)
  el = super(name)
  
  self.names.each{ |n|
      name_el = REXML::Element.new("#{obj_ns.prefix}:Name")
      name_el.text = n
      el.add_element(name_el)
  } if self.names
  
  self.concepts.each{ |c|
    concept_el = REXML::Element.new("#{obj_ns.prefix}:Concept")
    concept_el.text = c
    el.add_element(concept_el)
  } if self.concepts
  
  el.attributes["#{obj_ns.prefix}:probability"] = self.probability.to_s if self.probability
  el.attributes["#{obj_ns.prefix}:relation"] = self.relation if self.relation
  
  el
end