Class: VORuby::VOTables::VOTable::Meta::Field
- Defined in:
- lib/voruby/votables/meta.rb,
lib/voruby/votables/transforms.rb,
lib/voruby/votables/rexml_parser.rb,
lib/voruby/votables/libxml_parser.rb
Overview
A class representing the standard VOTable FIELD element.
Instance Attribute Summary collapse
-
#arraysize ⇒ Object
readonly
Returns the value of attribute arraysize.
-
#datatype ⇒ Object
readonly
Returns the value of attribute datatype.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#Type ⇒ Object
readonly
Returns the value of attribute Type.
-
#ucd ⇒ Object
readonly
Returns the value of attribute ucd.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
-
#uType ⇒ Object
readonly
Returns the value of attribute uType.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name = nil, datatype = nil, ucd = nil, unit = nil, description = nil, values = nil, links = [], id = nil, precision = nil, utype = nil, width = nil, ref = nil, arraysize = nil, type = nil) ⇒ Field
constructor
- name:
-
The name of the field.
- #to_s ⇒ Object
Constructor Details
#initialize(name = nil, datatype = nil, ucd = nil, unit = nil, description = nil, values = nil, links = [], id = nil, precision = nil, utype = nil, width = nil, ref = nil, arraysize = nil, type = nil) ⇒ Field
- name:
-
The name of the field.
- datatype:
-
The datatype of the field (Type: Type::DataType).
- ucd:
-
The UCD of the field (Type: Type::UCDType).
- unit:
-
The units of the value.
- description:
-
A description of the field (Type: VOTALE::Meta::Description).
- values:
-
Domain values for the field (Type: Meta::Values).
- links:
-
A collection of links associated with the field (Type: VOTable:Meta::Values).
- id:
-
A unique identifier for the field.
- precision:
-
The precision of the field (Type: Meta::PrecisionType).
- utype:
-
The unique type of the field.
- width:
-
The number of characters to use for input or output (Type: Type::PositiveInteger).
- ref:
-
A reference to another field.
- arraysize:
-
The arraysize definition for the field (Type: Type::ArrayDef).
- type:
-
The type of the field (Type: Type::FieldType).
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/voruby/votables/meta.rb', line 423 def initialize(name=nil, datatype=nil, ucd=nil, unit=nil, description=nil, values=nil, links=[], id=nil, precision=nil, utype=nil, width=nil, ref=nil, arraysize=nil, type=nil) raise "Field must define a data type" if datatype == nil #raise "Field must define a name" if name == nil @name = name Misc::TypeCheck.new(datatype, Type::DataType).check() @datatype = datatype Misc::TypeCheck.new(ucd, Type::UCDType).check() @ucd = ucd @unit = unit Misc::TypeCheck.new(description, Meta::Description).check() @description = description Misc::TypeCheck.new(values, Meta::Values).check() @values = values links.each{ |link| Misc::TypeCheck.new(link, Meta::Link).check() } @links = links @id = id Misc::TypeCheck.new(precision, Type::PrecisionType).check() @precision = precision @utype = utype Misc::TypeCheck.new(width, Type::PositiveInteger).check() @width = width @ref = ref Misc::TypeCheck.new(arraysize, Type::ArrayDef).check() @arraysize = arraysize Misc::TypeCheck.new(type, Type::FieldType).check() @type = type end |
Instance Attribute Details
#arraysize ⇒ Object (readonly)
Returns the value of attribute arraysize.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def arraysize @arraysize end |
#datatype ⇒ Object (readonly)
Returns the value of attribute datatype.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def datatype @datatype end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def id @id end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def links @links end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def name @name end |
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def precision @precision end |
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def ref @ref end |
#Type ⇒ Object (readonly)
Returns the value of attribute Type.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def Type @Type end |
#ucd ⇒ Object (readonly)
Returns the value of attribute ucd.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def ucd @ucd end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def unit @unit end |
#uType ⇒ Object (readonly)
Returns the value of attribute uType.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def uType @uType end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def values @values end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
391 392 393 |
# File 'lib/voruby/votables/meta.rb', line 391 def width @width end |
Class Method Details
.from_soap_obj(mfields) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/voruby/votables/transforms.rb', line 219 def self.from_soap_obj(mfields) mfields = [mfields] if !mfields.respond_to?(:each) fields = [] mfields.each do |mfield| datatype_txt = VOTable::_find_attr_value(mfield.__xmlattr, 'datatype') ucd_txt = VOTable::_find_attr_value(mfield.__xmlattr, 'ucd') precision_txt = VOTable::_find_attr_value(mfield.__xmlattr, 'precision') width_txt = VOTable::_find_attr_value(mfield.__xmlattr, 'width') arraysize_txt = VOTable::_find_attr_value(mfield.__xmlattr, 'arraysize') type_txt = VOTable::_find_attr_value(mfield.__xmlattr, 'type') fields.push(Field.new( VOTable::_find_attr_value(mfield.__xmlattr, 'name'), (datatype_txt == nil)? nil: Type::DataType.new(datatype_txt), (ucd_txt == nil)? nil: Type::UCDType.new(ucd_txt), VOTable::_find_attr_value(mfield.__xmlattr, 'unit'), (mfield.respond_to?(:dESCRIPTION))? Description.from_soap_obj(mfield.dESCRIPTION): nil, (mfield.respond_to?(:vALUES))? Values.from_soap_obj(mfield.vALUES): nil, (mfield.respond_to?(:lINK))? Link.from_soap_obj(mfield.lINK): [], VOTable::_find_attr_value(mfield.__xmlattr, 'ID'), (precision_txt == nil)? nil: Type::PrecisionType.new(precision_txt), VOTable::_find_attr_value(mfield.__xmlattr, 'utype'), (width_txt == nil)? nil: Type::PositiveInteger.new(width_txt.to_i), VOTable::_find_attr_value(mfield.__xmlattr, 'ref'), (arraysize_txt == nil)? nil: Type::ArrayDef.new(arraysize_txt), (type_txt == nil)? nil: Type::FieldType.new(type_txt) )) end fields end |
.from_xml(node) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/voruby/votables/rexml_parser.rb', line 161 def self.from_xml(node) # Attributes id = node.attributes['ID'] if node.attributes['ID'] unit = node.attributes['unit'] if node.attributes['unit'] datatype = Type::DataType.new(node.attributes['datatype']) if node.attributes['datatype'] precision = Type::PrecisionType.new(node.attributes['precision']) if node.attributes['precision'] width = Type::PositiveInteger.new(node.attributes['width'].to_i) if node.attributes['width'] ref = node.attributes['ref'] if node.attributes['ref'] name = node.attributes['name'] if node.attributes['name'] ucd = Type::UCDType.new(node.attributes['ucd']) if node.attributes['ucd'] arraysize = Type::ArrayDef.new(node.attributes['arraysize']) if node.attributes['arraysize'] type = Type::FieldType.new(node.attributes['type']) if node.attributes['type'] utype = node.attributes['utype'] if node.attributes['utype'] # Elements description = Meta::Description.from_xml(node.elements.to_a('DESCRIPTION').first) if node.elements['DESCRIPTION'] values = Meta::Values.from_xml(node.elements.to_a('VALUES').first) if node.elements['VALUES'] links = [] node.elements.each('LINK'){ |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 |
Instance Method Details
#to_s ⇒ Object
470 471 472 473 474 475 476 477 478 |
# File 'lib/voruby/votables/meta.rb', line 470 def to_s links = @links.collect{|x| x.to_s}.join('|') "{name=#{@name};datatype=#{@datatype};" + "ucd=#{@ucd};unit=#{@unit};description=#{@description};" + "values=#{@values};links=#{links};" + "id=#{@id};precision=#{@precision};utype=#{@utype};width=#{@width};" + "ref=#{@ref};arraysize=#{@arraysize};type=#{@type}}" end |