Class: VORuby::VOTable::V1_0::Data

Inherits:
Base show all
Defined in:
lib/voruby/votable/1.0/votable.rb

Overview

The actual tabular data.

Constant Summary collapse

ELEMENT_NAME =
'DATA'

Instance Attribute Summary

Attributes inherited from XML::Object::Base

#node

Instance Method Summary collapse

Methods inherited from Base

#==, element_name, #get_element, #xpath_for

Methods inherited from XML::Object::Base

#==, element_name, from_file, #to_s

Constructor Details

#initialize(defn = nil) ⇒ Data

Create a new body of data.

data = Data.new(:format => TableData.new())


1425
1426
1427
# File 'lib/voruby/votable/1.0/votable.rb', line 1425

def initialize(defn=nil)
  super(defn)
end

Instance Method Details

#formatObject

Retrieve the formatted data. May be TableData, Binary or Fits.



1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
# File 'lib/voruby/votable/1.0/votable.rb', line 1430

def format
  format_node = self.node.find_first("#{xpath_for(TableData)}|#{xpath_for(Binary)}|#{xpath_for(Fits)}")
  return nil if !format_node
  
  case format_node.name
    when 'TABLEDATA'    then TableData.new(format_node)
    when 'BINARY'       then Binary.new(format_node)
    when 'FITS'         then Fits.new(format_node)
    else                nil
  end
end

#format=(f) ⇒ Object

Set the formatted data. Must be one of the allowed data formats–TableData, Binary or Fits.



1444
1445
1446
1447
1448
1449
1450
1451
# File 'lib/voruby/votable/1.0/votable.rb', line 1444

def format=(f)
  raise 'Data format must be one of TableData, Binary or Fits' if ![TableData, Binary, Fits].include?(f.class)
  
  self.node.each_child do |c|
    c.remove!
  end
  set_element(f.class, f)
end