module VORuby module VOTables module VOTable require 'voruby/votables/votable' require 'voruby/votables/rexml_parser' # 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 class RexmlParsedVOTable attr_reader :path, :votable # [_path_:] # The path to the VOTable XML file to parse. 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 # Convert a RexmlParsedVOTable into a string representation. def to_s "{file=#{@path};votable=#{@votable}}" end end end end end