Class: VORuby::VOTables::VOTable::RexmlParsedVOTable
- Defined in:
- lib/voruby/votables/rexml_votable.rb
Overview
A wrapper around VOTable::VOTable that uses ruby’s built in rexml library to parse XML. Typically one would use VOTABLE::TreeParsedVOTable rather than using this class directly.
rexml_votable = VOTable::RexmlParsedVOTable('my_votable.xml')
votable = rexml_votable.votable
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#votable ⇒ Object
readonly
Returns the value of attribute votable.
Instance Method Summary collapse
-
#initialize(path) ⇒ RexmlParsedVOTable
constructor
- path:
-
The path to the VOTable XML file to parse.
-
#to_s ⇒ Object
Convert a RexmlParsedVOTable into a string representation.
Constructor Details
#initialize(path) ⇒ RexmlParsedVOTable
- path:
-
The path to the VOTable XML file to parse.
18 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/rexml_votable.rb', line 18 def initialize(path) @path = path file = File.new(path) doc = REXML::Document.new(file) root = doc.root # Root document # Attributes id = root.attributes['ID'] if root.attributes['ID'] version = root.attributes['version'] if root.attributes['version'] # Elements description = Meta::Description.from_xml(root.elements.to_a('DESCRIPTION').first) if root.elements['DESCRIPTION'] definition = Meta::Definitions.from_xml(root.elements.to_a('DEFINITIONS').first) if root.elements['DEFINITIONS'] coosys = [] root.elements.each('COOSYS'){ |sys| coosys.push(Meta::CooSys.from_xml(sys)) } params = [] root.elements.each('PARAM'){ |param| params.push(Meta::Param.from_xml(param)) } info = [] root.elements.each('INFO'){ |inf| info.push(Meta::Info.from_xml(inf)) } resources = [] root.elements.each('RESOURCE'){ |res| resources.push(Meta::Resource.from_xml(res)) } @votable = VOTable.new(id, version, description, definition, coosys, params, info, resources) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/voruby/votables/rexml_votable.rb', line 14 def path @path end |
#votable ⇒ Object (readonly)
Returns the value of attribute votable.
14 15 16 |
# File 'lib/voruby/votables/rexml_votable.rb', line 14 def votable @votable end |
Instance Method Details
#to_s ⇒ Object
Convert a RexmlParsedVOTable into a string representation.
59 60 61 |
# File 'lib/voruby/votables/rexml_votable.rb', line 59 def to_s "{file=#{@path};votable=#{@votable}}" end |