module VORuby module VOTables module VOTable require 'xml/libxml' module Meta class Description def self.from_xml(node) return Meta::Description.new(node.to_s) end end class Definitions def self.from_xml(node) systems = [] node.find('COOSYS').each { |sysNode| systems.push(Meta::CooSys.from_xml(sysNode)) } params = [] node.find('PARAM').each { |paramNode| params.push(Meta::Param.from_xml(paramNode)) } return self.new(systems, params) end end class CooSys def self.from_xml(node) id = node['ID'] equinox = Type::AstroYear.new(node['equinox']) if node['equinox'] epoch = Type::AstroYear.new(node['epoch']) if node['epoch'] system = Type::CoordSystemType.new(node['system']) if node['system'] return self.new(id, equinox, epoch, system) end end class Link def self.from_xml(node) id = node['ID'] content_role = Type::ContentRole.new(node['content-role']) if node['content-role'] content_type = node['content-type'] title = node['title'] value = node['value'] href = Type::AnyURI.new(node['href']) if node['href'] gref = node['gref'] action = Type::AnyURI.new(node['action']) if node['action'] return self.new(href, value, title, action, id, content_type, content_role, gref) end end class Values def self.from_xml(node) # Attributes id = node['ID'] if node['ID'] type = Type::ValuesType.new(node['type']) if node['type'] null = node['null'] if node['null'] ref = node['ref'] if node['ref'] # Elements min = Meta::Min.from_xml(node.find('MIN').to_a.first) if node.find('MIN').length > 0 max = Meta::Max.from_xml(node.find('MAX').to_a.first) if node.find('MAX').length > 0 options = [] node.find('OPTION').each { |optNode| options.push(Meta::Option.from_xml(optNode)) } return self.new(min, max, options, id, type, null, ref) end end class FieldRef def self.from_xml(node) ref = node['ref'] if node['ref'] return self.new(ref) end end class ParamRef def self.from_xml(node) ref = node['ref'] if node['ref'] return self.new(ref) end end class Group def self.from_xml(node) # Attributes id = node['ID'] if node['ID'] name = node['name'] if node['name'] ref = node['ref'] if node['ref'] ucd = UCDType.new(node['ucd']) if node['ucd'] utype = node['utype'] if node['utype'] # Elements description = Meta::Description.from_xml(node.find('DESCRIPTION').to_a.first) if node.find('DESCRIPTION').length > 0 fieldrefs = [] node.find('FIELDref').each { |fref| fieldrefs.push(Meta::FieldRef.from_xml(fref)) } paramrefs = [] node.find('PARAMref').each { |pref| paramrefs.push(Meta::ParamRef.from_xml(pref)) } params = [] node.find('PARAM').each { |param| params.push(Meta::Param.from_xml(param)) } groups = [] node.find('GROUP').each { |group| groups.push(Meta::Group.from_xml(group)) } return self.new(name, ucd, description, fieldrefs, paramrefs, params, groups, id, ref, utype) end end class Param def self.from_xml(node) # Attributes id = node['ID'] if node['ID'] unit = node['unit'] if node['unit'] datatype = Type::DataType.new(node['datatype']) if node['datatype'] precision = Type::PrecisionType.new(node['precision']) if node['precision'] width = Type::PositiveInteger.new(node['width'].to_i) if node['width'] ref = node['ref'] if node['ref'] name = node['name'] if node['name'] ucd = Type::UCDType.new(node['ucd']) if node['ucd'] utype = node['utype'] if node['utype'] value = node['value'] if node['value'] arraysize = Type::ArrayDef.new(node['arraysize']) if node['arraysize'] # Elements description = Meta::Description.from_xml(node.find('DESCRIPTION').to_a.first) if node.find('DESCRIPTION').length > 0 values = Meta::Values.from_xml(node.find('VALUES').to_a.first) if node.find('VALUES').length > 0 links = [] node.find('LINK').each { |linkNode| links.push(Meta::Link.from_xml(linkNode)) } return self.new(name, datatype, value, ucd, unit, description, values, links, id, precision, utype, width, ref, arraysize) end end class Field def self.from_xml(node) # Attributes id = node['ID'] if node['ID'] unit = node['unit'] if node['unit'] datatype = Type::DataType.new(node['datatype']) if node['datatype'] precision = Type::PrecisionType.new(node['precision']) if node['precision'] width = Type::PositiveInteger.new(node['width'].to_i) if node['width'] ref = node['ref'] if node['ref'] name = node['name'] if node['name'] ucd = Type::UCDType.new(node['ucd']) if node['ucd'] arraysize = Type::ArrayDef.new(node['arraysize']) if node['arraysize'] type = Type::FieldType.new(node['type']) if node['type'] utype = node['utype'] if node['utype'] # Elements description = Meta::Description.from_xml(node.find('DESCRIPTION').to_a.first) if node.find('DESCRIPTION').length > 0 values = Meta::Values.from_xml(node.find('VALUES').to_a.first) if node.find('VALUES').length > 0 links = [] node.find('LINK').each { |link| links.push(Meta::Link.from_xml(link)) } return self.new(name, datatype, ucd, unit, description, values, links, id, precision, utype, width, ref, arraysize, type) end end class Info def self.from_xml(node) id = node['ID'] name = node['name'] value = node['value'] return self.new(name, value, id) end end class Table def self.from_xml(node) # Attributes id = node['ID'] if node['ID'] name = node['name'] if node['name'] ref = node['ref'] if node['ref'] ucd = UCDType.new(node['ucd']) if node['ucd'] utype = node['utype'] if node['utype'] nrows = NonNegativeInteger.new(node['nrows'].to_i) if node['nrows'] # Elements description = Meta::Description.from_xml(node.find('DESCRIPTION').to_a.first) if node.find('DESCRIPTION').length > 0 fields = [] node.find('FIELD').each { |fieldNode| fields.push(Meta::Field.from_xml(fieldNode)) } params = [] node.find('PARAM').each { |paramNode| params.push(Meta::Param.from_xml(paramNode)) } groups = [] node.find('GROUP').each { |groupNode| params.push(Meta::Group.from_xml(groupNode)) } links = [] node.find('LINK').each { |linkNode| params.push(Meta::Link.from_xml(linkNode)) } data = Data::Data.from_xml(node.find('DATA').to_a.first) if node.find('DATA').length > 0 return self.new(name, id, ucd, utype, ref, nrows, description, fields, params, groups, links, data) end end class Resource def self.from_xml(node) # Attributes name = node['name'] if node['name'] id = node['ID'] if node['ID'] utype = node['utype'] if node['utype'] type = Type::ResourceType.new(node['type']) if node['type'] # Elements description = Meta::Description.from_xml(node.find('DESCRIPTION').to_a.first) if node.find('DESCRIPTION').length > 0 info = [] node.find('INFO').each { |infoNode| info.push(Meta::Info.from_xml(infoNode)) } systems = [] node.find('COOSYS').each { |sysNode| systems.push(Meta::CooSys.from_xml(sysNode)) } params = [] node.find('PARAM').each { |paramNode| params.push(Meta::Param.from_xml(paramNode)) } resources = [] node.find('RESOURCE').each { |resNode| resources.push(Meta::Resource.from_xml(resNode)) } links = [] node.find('LINK').each { |linkNode| links.push(Meta::Link.from_xml(linkNode)) } tables = [] node.find('TABLE').each { |tblNode| tables.push(Meta::Table.from_xml(tblNode)) } return self.new(name, id, utype, type, description, info, systems, params, links, tables, resources) end end class Option def self.from_xml(node) value = node['value'] if node['value'] name = node['name'] if node['name'] options = [] node.find('OPTION').each { |optNode| options.push(Meta::Option.from_xml(optNode)) } return self.new(value, name, options) end end class Max def self.from_xml(node) value = node['node'] if node['node'] inclusive = Type::YesNo.new(node['inclusive']) if node['inclusive'] return self.new(value, inclusive) end end class Min def self.from_xml(node) value = node['node'] if node['node'] inclusive = Type::YesNo.new(node['inclusive']) if node['inclusive'] return self.new(value, inclusive) end end end module Data class Stream def self.from_xml(node) href = Type::AnyURI.new(node['href']) if node['href'] expires = DateTime.parse(node['expires']) if node['expires'] rights = node['rights'] type = Type::StreamType.new(node['type']) if node['type'] actuate = Actuate.new(node['actuate']) if node['actuate'] encoding = Type::EncodingType.new(node['encoding']) if node['encoding'] return self.new(href, expires, rights, type, actuate, encoding) end end class BinaryStream def self.from_xml(node) stream = Stream.from_xml(node.find('STREAM').to_a.first) return self.new(stream) end end class FITSStream def self.from_xml(node) stream = Stream.from_xml(node.find('STREAM').to_a.first) extnum = Type::PositiveInteger.new(node['extnum'].to_i) if node['extnum'] return self.new(stream, extnum) end end class TD def self.from_xml(node) value = node.to_s encoding = Type::EncodingType.new(node['encoding']) if node['encoding'] return self.new(value, encoding) end end class TR def self.from_xml(node) tds = [] node.find('TD').each { |tdNode| tds.push(TD.from_xml(tdNode)) } return self.new(tds) end end class TableData def self.from_xml(node) trs = [] node.find('TR').each { |trNode| trs.push(TR.from_xml(trNode)) } return self.new(trs) end end class Data def self.from_xml(node) format = nil node.find('FITS').each { |fnode| format = FITSStream.from_xml(fnode) } node.find('BINARY').each { |bnode| format = BinaryStream.from_xml(bode) } node.find('TABLEDATA').each { |tnode| format = TableData.from_xml(tnode) } return self.new(format) end end end end end end