Class: VORuby::VOEvent::V1_1::Who

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

Defined Under Namespace

Classes: AuthorList, DateTimeList, IVORNList

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(author_ivorns, dates, authors = nil, descriptions = nil, references = nil) ⇒ Who

Returns a new instance of Who.



916
917
918
919
920
921
# File 'lib/voruby/voevent/1.1/voevent.rb', line 916

def initialize(author_ivorns, dates, authors=nil, descriptions=nil, references=nil)
  super(descriptions, references)
  self.author_ivorns = author_ivorns
  self.dates = dates
  self.authors = authors
end

Instance Attribute Details

#author_ivornsObject

Returns the value of attribute author_ivorns.



914
915
916
# File 'lib/voruby/voevent/1.1/voevent.rb', line 914

def author_ivorns
  @author_ivorns
end

#authorsObject

Returns the value of attribute authors.



914
915
916
# File 'lib/voruby/voevent/1.1/voevent.rb', line 914

def authors
  @authors
end

#datesObject

Returns the value of attribute dates.



914
915
916
# File 'lib/voruby/voevent/1.1/voevent.rb', line 914

def dates
  @dates
end

Class Method Details

.from_xml(xml) ⇒ Object



978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
# File 'lib/voruby/voevent/1.1/voevent.rb', line 978

def self.from_xml(xml)
  root = element_from(xml)
  
  author_ivorns = REXML::XPath.match(root, 'x:AuthorIVORN', {'x' => obj_ns.uri})
  author_ivorns = nil if author_ivorns.size == 0
  
  dates = REXML::XPath.match(root, 'x:Date', {'x' => obj_ns.uri})
  dates = nil if dates.size == 0
  
  authors = REXML::XPath.match(root, 'x:Author', {'x' => obj_ns.uri})
  authors = nil if authors.size == 0
  
  self.new(
    author_ivorns ? IVORNList.new(author_ivorns.collect{ |i| URI.parse(i.text) }) : nil,
    dates ? DateTimeList.new(dates.collect{ |d| DateTime.parse(d.text) }) : nil,
    authors ? AuthorList.new(authors.collect{ |a| Author.from_xml(a) }) : nil,
    *Described.described_from_xml(root)
  )
end

Instance Method Details

#==(w) ⇒ Object



950
951
952
953
954
955
# File 'lib/voruby/voevent/1.1/voevent.rb', line 950

def ==(w)
  super(w) and
  self.author_ivorns == w.author_ivorns and
  self.dates == w.dates and
  self.authors == w.authors
end

#to_xml(name = nil) ⇒ Object



957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
# File 'lib/voruby/voevent/1.1/voevent.rb', line 957

def to_xml(name=nil)
  el = super(name)
  
  self.author_ivorns.each{ |i|
    e = REXML::Element.new("#{obj_ns.prefix}:AuthorIVORN")
    e.text = i.to_s
    el.add_element(e)
  } if self.author_ivorns
  
  self.dates.each{ |d|
    e = REXML::Element.new("#{obj_ns.prefix}:Date")
    e.text = d.to_s
    el.add_element(e)
  } if self.dates
  
  self.authors.each{ |a| el.add_element(a.to_xml('Author')) } if self.authors
  
  collapse_namespaces(el)
  el
end