Class: VORuby::VOTables::VOTable::LibxmlParsedVOTable

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

Overview

A wrapper around VOTable::VOTable that uses the libxml2 library and its corresponding bindings to parse XML. Typically one would use VOTable::TreeParsedVOTable rather than using this class directly.

libxml_votable = VOTable::LibxmlParsedVOTable('my_votable.xml')
votable = libxml_votable.votable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ LibxmlParsedVOTable

path:

The path to the VOTable XML file to parse.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/voruby/votables/libxml_votable.rb', line 19

def initialize(path)
  @path = path ;
  doc = XML::Document.file(path)

  root = doc.root # Root document

  # Attributes
  id = root['ID'] if root['ID']
  version = root['version'] if root['version']

  # Elements
  description =
  Meta::Description.from_xml(root.find('DESCRIPTION').to_a.first) if root.find('DESCRIPTION').length > 0
  definition =
  Meta::Definitions.from_xml(root.find('DEFINITIONS').to_a.first) if root.find('DEFINITIONS').length > 0

  coosys = []
  root.find('COOSYS').each { |sys|
    coosys.push(Meta::CooSys.from_xml(sys))
  }

  params = []
  root.find('PARAM').each { |param|
    params.push(Meta::Param.from_xml(param))
  }

  info = []
  root.find('INFO').each { |inf|
    info.push(Meta::Info.from_xml(inf))
  }
      
  resources = []
  root.find('RESOURCE').each { |res|
    resources.push(Meta::Resource.from_xml(res))
  }

  @votable = VOTable.new(id, version, description, definition, coosys, params, info, resources)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



15
16
17
# File 'lib/voruby/votables/libxml_votable.rb', line 15

def path
  @path
end

#votableObject (readonly)

Returns the value of attribute votable.



15
16
17
# File 'lib/voruby/votables/libxml_votable.rb', line 15

def votable
  @votable
end

Instance Method Details

#to_sObject

Convert a LibxmlParsedVOTable into a string representation.



59
60
61
# File 'lib/voruby/votables/libxml_votable.rb', line 59

def to_s
  "{file=#{@path};votable=#{@votable}}"
end