Class: VORuby::VOTable::Base

Inherits:
XML::Object::Base show all
Defined in:
lib/voruby/votable/votable.rb

Overview

The base class that all VOTable domain objects derive from. You’ll never instantiate this directly.

Instance Attribute Summary

Attributes inherited from XML::Object::Base

#node

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XML::Object::Base

from_file, #initialize, #to_s

Constructor Details

This class inherits a constructor from XML::Object::Base

Class Method Details

.element_nameObject

Get the name of the element when serialized to XML that the object in question will take on.



165
166
167
# File 'lib/voruby/votable/votable.rb', line 165

def self.element_name
  const_get('ELEMENT_NAME')
end

Instance Method Details

#==(obj) ⇒ Object

Equality among domain objects. Two objects are considered equal if they’re of the same class and their accessor methods themselves return objects which are equal.



186
187
188
189
190
191
192
193
194
# File 'lib/voruby/votable/votable.rb', line 186

def ==(obj)
  return false if self.class != obj.class
  
  self.methods_to_test_for_equality.each do |method|
    return false if self.send(method) != obj.send(method)
  end
 
  true
end

#get_element(klass) ⇒ Object

Retrieve the domain object that corresponds to the specified class.



177
178
179
180
# File 'lib/voruby/votable/votable.rb', line 177

def get_element(klass)
  subnode = self.node.find_first("*[local-name()='#{klass.element_name}']")
  subnode ? klass.new(subnode) : nil
end

#xpath_for(klass) ⇒ Object

Determine the xpath corresponding to the specified class.

obj.xpath_for(Field)  # => "*[local-name()='FIELD']"


171
172
173
# File 'lib/voruby/votable/votable.rb', line 171

def xpath_for(klass)
  "*[local-name()='#{klass.element_name}']"
end