Class: VORuby::VOEvent::V1_1::Why

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

Overview

Initial scientific assessment.

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(inferences, importance = nil, expires = nil, names = nil, concepts = nil, descriptions = nil, references = nil) ⇒ Why

Returns a new instance of Why.



378
379
380
381
382
383
384
385
# File 'lib/voruby/voevent/1.1/voevent.rb', line 378

def initialize(inferences, importance=nil, expires=nil, names=nil, concepts=nil, descriptions=nil, references=nil)
  super(descriptions, references)
  self.inferences = inferences
  self.importance = importance
  self.expires = expires
  self.names = names
  self.concepts = concepts
end

Instance Attribute Details

#conceptsObject

Returns the value of attribute concepts.



376
377
378
# File 'lib/voruby/voevent/1.1/voevent.rb', line 376

def concepts
  @concepts
end

#expiresObject

Returns the value of attribute expires.



376
377
378
# File 'lib/voruby/voevent/1.1/voevent.rb', line 376

def expires
  @expires
end

#importanceObject

Returns the value of attribute importance.



376
377
378
# File 'lib/voruby/voevent/1.1/voevent.rb', line 376

def importance
  @importance
end

#inferencesObject

Returns the value of attribute inferences.



376
377
378
# File 'lib/voruby/voevent/1.1/voevent.rb', line 376

def inferences
  @inferences
end

#namesObject

Returns the value of attribute names.



376
377
378
# File 'lib/voruby/voevent/1.1/voevent.rb', line 376

def names
  @names
end

Class Method Details

.from_xml(xml) ⇒ Object



461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/voruby/voevent/1.1/voevent.rb', line 461

def self.from_xml(xml)
  root = element_from(xml)
  
  inferences = REXML::XPath.match(root, 'x:Inference', {'x' => obj_ns.uri})
  inferences = nil if inferences.size == 0
  
  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
  
  importance = root.attributes.get_attribute_ns(obj_ns.uri, 'importance')
  expires = root.attributes.get_attribute_ns(obj_ns.uri, 'expires')
  
  self.new(
    inferences ? InferenceList.new(inferences.collect{ |i| Inference.from_xml(i) }) : nil,
    importance ? Float(importance.value) : nil,
    expires ? DateTime.parse(expires.value) : nil,
    names ? NameList.new(names.collect{ |n| n.text }) : nil,
    concepts ? ConceptList.new(concepts.collect{ |c| c.text }) : nil,
    *Described.described_from_xml(root)
  )
end

Instance Method Details

#==(w) ⇒ Object



428
429
430
431
432
433
434
435
# File 'lib/voruby/voevent/1.1/voevent.rb', line 428

def ==(w)
  super(w) and
  self.inferences == w.inferences and
  self.importance == w.importance and
  self.expires == w.expires and
  self.names == w.names and
  self.concepts == w.concepts
end

#to_xml(name = nil) ⇒ Object



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/voruby/voevent/1.1/voevent.rb', line 437

def to_xml(name=nil)
  el = super(name)
  
  self.inferences.each{ |i| el.add_element(i.to_xml('Inference')) } if self.inferences
  
  el.attributes["#{obj_ns.prefix}:importance"] = self.importance.to_s if self.importance
  el.attributes["#{obj_ns.prefix}:expires"] = self.expires.strftime('%Y-%m-%dT%H:%M:%S') if self.expires
  
  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
  
  collapse_namespaces(el)
  el
end