Class: VORuby::VOEvent::V1_1::Reference

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

Overview

External content.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(uri, type = 'url', name = nil) ⇒ Reference

Returns a new instance of Reference.



19
20
21
22
23
# File 'lib/voruby/voevent/1.1/voevent.rb', line 19

def initialize(uri, type='url', name=nil)
  self.uri = uri
  self.type = type || 'url'
  self.name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/voruby/voevent/1.1/voevent.rb', line 16

def name
  @name
end

#typeObject

Returns the value of attribute type.



16
17
18
# File 'lib/voruby/voevent/1.1/voevent.rb', line 16

def type
  @type
end

#uriObject

Returns the value of attribute uri.



17
18
19
# File 'lib/voruby/voevent/1.1/voevent.rb', line 17

def uri
  @uri
end

Class Method Details

.from_xml(xml) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/voruby/voevent/1.1/voevent.rb', line 46

def self.from_xml(xml)
  root = element_from(xml)
  
  name = root.attributes.get_attribute_ns(obj_ns.uri, 'name')
  type = root.attributes.get_attribute_ns(obj_ns.uri, 'type')
  
  self.new(
    URI.parse(root.attributes.get_attribute_ns(obj_ns.uri, 'uri').value),
    type ? type.value : nil,
    name ? name.value : nil
  )
end

Instance Method Details

#==(r) ⇒ Object



30
31
32
33
34
# File 'lib/voruby/voevent/1.1/voevent.rb', line 30

def ==(r)
  self.uri == r.uri and
  self.type == r.type and
  self.name == r.name
end

#to_xml(name = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/voruby/voevent/1.1/voevent.rb', line 36

def to_xml(name=nil)
  el = element(name)
  
  el.attributes["#{obj_ns.prefix}:uri"] = self.uri.to_s
  el.attributes["#{obj_ns.prefix}:name"] = self.name.to_s if self.name
  el.attributes["#{obj_ns.prefix}:type"] = self.type.to_s if self.type
  
  el
end