Class: VORuby::VOTable::V1_0::Table
- Inherits:
-
Base
- Object
- XML::Object::Base
- Base
- VORuby::VOTable::V1_0::Table
- Defined in:
- lib/voruby/votable/1.0/votable.rb
Overview
The basic structure of a votable. Essentially, tablular data + a description of the columns of that data.
Constant Summary collapse
- ELEMENT_NAME =
'TABLE'
Instance Attribute Summary
Attributes inherited from XML::Object::Base
Class Method Summary collapse
Instance Method Summary collapse
-
#data ⇒ Object
Retrieve the data (Data).
-
#data=(d) ⇒ Object
Set the data (Data).
-
#description ⇒ Object
Retrieve the description (Description).
-
#description=(d) ⇒ Object
Set the description (Description).
-
#fields ⇒ Object
Retrieve the fields (Field), a.k.a.
-
#fields=(flds) ⇒ Object
Set the fields.
- #id ⇒ Object
- #id=(i) ⇒ Object
-
#initialize(defn = nil) ⇒ Table
constructor
Create a new table.
-
#links ⇒ Object
Retrieve the links (Link).
-
#links=(lnks) ⇒ Object
Set the links (Link).
- #name ⇒ Object
- #name=(n) ⇒ Object
- #ref ⇒ Object
- #ref=(r) ⇒ Object
-
#to_html ⇒ Object
Convert the table into HTML.
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) ⇒ Table
Create a new table. table = Table.new( :name => 'results', :fields => [Field.new()], :data => Data.new(:format => TableData.new()) )
800 801 802 |
# File 'lib/voruby/votable/1.0/votable.rb', line 800 def initialize(defn=nil) super(defn) end |
Class Method Details
.serialization_order ⇒ Object
787 788 789 790 791 792 |
# File 'lib/voruby/votable/1.0/votable.rb', line 787 def self.serialization_order [ :description, :fields, :links, :data, :id, :name, :ref ] end |
Instance Method Details
#data ⇒ Object
Retrieve the data (Data).
839 840 841 |
# File 'lib/voruby/votable/1.0/votable.rb', line 839 def data get_element(Data) end |
#data=(d) ⇒ Object
Set the data (Data).
844 845 846 |
# File 'lib/voruby/votable/1.0/votable.rb', line 844 def data=(d) set_element(Data, d) end |
#description ⇒ Object
Retrieve the description (Description).
829 830 831 |
# File 'lib/voruby/votable/1.0/votable.rb', line 829 def description get_element(Description) end |
#description=(d) ⇒ Object
Set the description (Description).
834 835 836 |
# File 'lib/voruby/votable/1.0/votable.rb', line 834 def description=(d) set_element(Description, d) end |
#fields ⇒ Object
Retrieve the fields (Field), a.k.a. column descriptions. Returns a HomogeneousNodeList.
850 851 852 |
# File 'lib/voruby/votable/1.0/votable.rb', line 850 def fields HomogeneousNodeList.new(self.node, xpath_for(Field), Field) end |
#fields=(flds) ⇒ Object
Set the fields. table.fields = [Field.new(), ...]
856 857 858 |
# File 'lib/voruby/votable/1.0/votable.rb', line 856 def fields=(flds) self.fields.replace(flds) end |
#id ⇒ Object
804 805 806 |
# File 'lib/voruby/votable/1.0/votable.rb', line 804 def id self.node['ID'] end |
#id=(i) ⇒ Object
808 809 810 |
# File 'lib/voruby/votable/1.0/votable.rb', line 808 def id=(i) @node['ID'] = i.to_s end |
#links ⇒ Object
Retrieve the links (Link). Returns a HomogeneousNodeList.
862 863 864 |
# File 'lib/voruby/votable/1.0/votable.rb', line 862 def links HomogeneousNodeList.new(self.node, xpath_for(Link), Link) end |
#links=(lnks) ⇒ Object
Set the links (Link). table.links = [Link.new(), ...]
868 869 870 |
# File 'lib/voruby/votable/1.0/votable.rb', line 868 def links=(lnks) self.links.replace(lnks) end |
#name ⇒ Object
812 813 814 |
# File 'lib/voruby/votable/1.0/votable.rb', line 812 def name self.node['name'] end |
#name=(n) ⇒ Object
816 817 818 |
# File 'lib/voruby/votable/1.0/votable.rb', line 816 def name=(n) @node['name'] = n.to_s end |
#ref ⇒ Object
820 821 822 |
# File 'lib/voruby/votable/1.0/votable.rb', line 820 def ref self.node['ref'] end |
#ref=(r) ⇒ Object
824 825 826 |
# File 'lib/voruby/votable/1.0/votable.rb', line 824 def ref=(r) @node['ref'] = r.to_s end |
#to_html ⇒ Object
Convert the table into HTML. Not all aspects of the votable are translated. table = Table.new( :id => 'table1', :description => Description.new(:text => 'A test table'), :fields => [ Field.new(:name => 'RA', :id => 'col1', :ucd => 'pos.eq.ra;meta.main', :ref => 'J2000', :datatype => 'float', :width => 6, :precision => '2', :unit => 'deg'), Field.new(:name => 'Dec', :id => 'col2', :ucd => 'pos.eq.dec;meta.main', :ref => 'J2000', :datatype => 'float', :width => 6, :precision => '2', :unit => 'deg'), Field.new(:name => 'Name', :id => 'col3', :ucd => 'meta.id;meta.main', :datatype => 'char', :arraysize => '8*') ], :data => Data.new( :format => TableData.new( :trs => [ Tr.new(:tds => [Td.new(:text => '123'), Td.new(:text => '456'), Td.new(:text => 'my_obj1')]), Tr.new(:tds => [Td.new(:text => '789'), Td.new(:text => '112'), Td.new(:text => 'my_obj2')]), Tr.new(:tds => [Td.new(:text => '145'), Td.new(:text => '178'), Td.new(:text => 'my_obj3')]) ] ) ) )
puts table.to_html # =>
|
RA
pos.eq.ra;meta.main
deg
float
|
Dec
pos.eq.dec;meta.main
deg
float
|
Name
meta.id;meta.main
char
8*
|
|---|---|---|
| 123 | 456 | my_obj1 |
| 789 | 112 | my_obj2 |
| 145 | 178 | my_obj3 |
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 |
# File 'lib/voruby/votable/1.0/votable.rb', line 945 def to_html builder = Builder::XmlMarkup.new(:indent => 2, :margin => 2) = {} [:id] = self.id if self.id builder.table() { |table| table.caption(self.description.text) if self.description table.thead { |thead| if self.fields.size > 0 thead.tr { |tr| self.fields.each do |field| tr.th { |th| th << field.to_html } end } end } if self.data and self.data.format table.tbody { |tbody| self.data.format.trs.each do |tr| tbody << tr.to_html end } end } end |