Class: VORuby::VOTables::VOTable::TreeParsedVOTable

Inherits:
Object
  • Object
show all
Defined in:
lib/voruby/votables/tree.rb

Overview

A VOTable parsed from a file using a DOM-like implementation of an XML parser. For example:

tree_votable = VOTable::TreeParsedVOTable.new('my_votable.xml', 'rexml')
real_votable = tree_votable.votable # Get the VOTable

As you can see, TreeParsedVOTable is basically a wrapper for VOTable.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, lib = 'rexml') ⇒ TreeParsedVOTable

path:

The path to a valid VOTable XML file.

lib:

The underlying library used to parse the XML. Current options are ‘rexml’ and ‘libxml’. Rexml is Ruby’s all-native XML parsing solution and is therefore shipped with every ruby release. It’s very convenient but slow on large files. Ruby also has available to it libxml2 bindings which can be installed separately. This is the recommended configuration for production systems as it is much faster.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/voruby/votables/tree.rb', line 23

def initialize(path, lib='rexml')
  @path = path
  @lib = lib

  @votable = nil
  if lib == 'libxml' # For a faster alternative, use libxml2
  require 'voruby/votables/libxml_votable'
  @votable = LibxmlParsedVOTable.new(@path)
  else # By default, we'll use Ruby's built-in native XML parser
  require 'voruby/votables/rexml_votable'
  @votable = RexmlParsedVOTable.new(@path)
  end
end

Instance Attribute Details

#libObject (readonly)

Returns the value of attribute lib.



12
13
14
# File 'lib/voruby/votables/tree.rb', line 12

def lib
  @lib
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/voruby/votables/tree.rb', line 12

def path
  @path
end

#votableObject (readonly)

Returns the value of attribute votable.



12
13
14
# File 'lib/voruby/votables/tree.rb', line 12

def votable
  @votable
end

Instance Method Details

#to_sObject

Convert the TreeParsedVOTable to a string representation.



38
39
40
# File 'lib/voruby/votables/tree.rb', line 38

def to_s
  "{lib=#{@lib};#{@votable}}"
end