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.



258
259
260
# File 'lib/voruby/votable/votable.rb', line 258

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.



279
280
281
282
283
284
285
286
287
# File 'lib/voruby/votable/votable.rb', line 279

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.



270
271
272
273
# File 'lib/voruby/votable/votable.rb', line 270

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']"


264
265
266
# File 'lib/voruby/votable/votable.rb', line 264

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