Class: VORuby::VOEvent::V1_1::Description

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

Overview

Human readable text.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(value, format = 'text/plain') ⇒ Description

Returns a new instance of Description.



65
66
67
68
# File 'lib/voruby/voevent/1.1/voevent.rb', line 65

def initialize(value, format='text/plain')
  self.value = value
  self.format = format || 'text/plain'
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



62
63
64
# File 'lib/voruby/voevent/1.1/voevent.rb', line 62

def format
  @format
end

#valueObject

Returns the value of attribute value.



63
64
65
# File 'lib/voruby/voevent/1.1/voevent.rb', line 63

def value
  @value
end

Class Method Details

.from_xml(xml) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/voruby/voevent/1.1/voevent.rb', line 89

def self.from_xml(xml)
  root = element_from(xml)
  
  format = root.attributes.get_attribute_ns(obj_ns.uri, 'format')
  
  self.new(
    root.texts.join('').strip,
    format ? format.value : nil
  )
end

Instance Method Details

#==(d) ⇒ Object



75
76
77
78
# File 'lib/voruby/voevent/1.1/voevent.rb', line 75

def ==(d)
  self.value == d.value and
  self.format == d.format
end

#to_xml(name = nil) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/voruby/voevent/1.1/voevent.rb', line 80

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