Class: VORuby::VOTable::V1_1::Table
- Inherits:
-
Base
- Object
- XML::Object::Base
- Base
- VORuby::VOTable::V1_1::Table
- Defined in:
- lib/voruby/votable/1.1/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.
-
#groups ⇒ Object
Retrieve the groups (Group).
-
#groups=(grps) ⇒ Object
Set the groups (Group).
- #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
-
#nrows ⇒ Object
Retrieve the number of rows in the table.
-
#nrows=(n) ⇒ Object
Set the number of rows in the table.
-
#params ⇒ Object
Retrieve the parameters (Param).
-
#params=(parameters) ⇒ Object
Set the parameters list (Param).
- #ref ⇒ Object
- #ref=(r) ⇒ Object
-
#to_html ⇒ Object
Convert the table into HTML.
- #ucd ⇒ Object
-
#ucd=(u) ⇒ Object
Set the unified content descriptor or UCD.
- #utype ⇒ Object
-
#utype=(u) ⇒ Object
Set the utype (i.e. the role of the column in the context of an external data model).
Methods inherited from Base
#==, element_name, #get_element, #xpath_for
Methods inherited from XML::Object::Base
#==, element_name, from_file, #to_s
Constructor Details
Class Method Details
.serialization_order ⇒ Object
815 816 817 818 819 820 |
# File 'lib/voruby/votable/1.1/votable.rb', line 815 def self.serialization_order [ :description, :params, :fields, :groups, :links, :data, :id, :name, :ucd, :utype, :ref, :nrows ] end |
Instance Method Details
#data ⇒ Object
Retrieve the data (Data).
896 897 898 |
# File 'lib/voruby/votable/1.1/votable.rb', line 896 def data get_element(Data) end |
#data=(d) ⇒ Object
Set the data (Data).
901 902 903 |
# File 'lib/voruby/votable/1.1/votable.rb', line 901 def data=(d) set_element(Data, d) end |
#description ⇒ Object
Retrieve the description (Description).
886 887 888 |
# File 'lib/voruby/votable/1.1/votable.rb', line 886 def description get_element(Description) end |
#description=(d) ⇒ Object
Set the description (Description).
891 892 893 |
# File 'lib/voruby/votable/1.1/votable.rb', line 891 def description=(d) set_element(Description, d) end |
#fields ⇒ Object
Retrieve the fields (Field), a.k.a. column descriptions. Returns a HomogeneousNodeList.
907 908 909 |
# File 'lib/voruby/votable/1.1/votable.rb', line 907 def fields HomogeneousNodeList.new(self.node, xpath_for(Field), Field) end |
#fields=(flds) ⇒ Object
Set the fields.
table.fields = [Field.new(), ...]
913 914 915 |
# File 'lib/voruby/votable/1.1/votable.rb', line 913 def fields=(flds) self.fields.replace(flds) end |
#groups ⇒ Object
Retrieve the groups (Group). Returns a HomogeneousNodeList.
931 932 933 |
# File 'lib/voruby/votable/1.1/votable.rb', line 931 def groups HomogeneousNodeList.new(self.node, xpath_for(Group), Group) end |
#groups=(grps) ⇒ Object
Set the groups (Group).
table.groups = [Group.new(), ...]
937 938 939 |
# File 'lib/voruby/votable/1.1/votable.rb', line 937 def groups=(grps) self.groups.replace(grps) end |
#id ⇒ Object
832 833 834 |
# File 'lib/voruby/votable/1.1/votable.rb', line 832 def id self.node['ID'] end |
#id=(i) ⇒ Object
836 837 838 |
# File 'lib/voruby/votable/1.1/votable.rb', line 836 def id=(i) @node['ID'] = i.to_s end |
#links ⇒ Object
Retrieve the links (Link). Returns a HomogeneousNodeList.
943 944 945 |
# File 'lib/voruby/votable/1.1/votable.rb', line 943 def links HomogeneousNodeList.new(self.node, xpath_for(Link), Link) end |
#links=(lnks) ⇒ Object
Set the links (Link).
table.links = [Link.new(), ...]
949 950 951 |
# File 'lib/voruby/votable/1.1/votable.rb', line 949 def links=(lnks) self.links.replace(lnks) end |
#name ⇒ Object
840 841 842 |
# File 'lib/voruby/votable/1.1/votable.rb', line 840 def name self.node['name'] end |
#name=(n) ⇒ Object
844 845 846 |
# File 'lib/voruby/votable/1.1/votable.rb', line 844 def name=(n) @node['name'] = n.to_s end |
#nrows ⇒ Object
Retrieve the number of rows in the table.
875 876 877 |
# File 'lib/voruby/votable/1.1/votable.rb', line 875 def nrows self.node['nrows'] ? self.node['nrows'].to_i : nil end |
#nrows=(n) ⇒ Object
Set the number of rows in the table. n should be an integer.
881 882 883 |
# File 'lib/voruby/votable/1.1/votable.rb', line 881 def nrows=(n) @node['nrows'] = n.to_s end |
#params ⇒ Object
Retrieve the parameters (Param). Returns a HomogeneousNodeList.
919 920 921 |
# File 'lib/voruby/votable/1.1/votable.rb', line 919 def params HomogeneousNodeList.new(self.node, xpath_for(Param), Param) end |
#params=(parameters) ⇒ Object
Set the parameters list (Param).
table.params = [Param.new(), ...]
925 926 927 |
# File 'lib/voruby/votable/1.1/votable.rb', line 925 def params=(parameters) self.params.replace(parameters) end |
#ref ⇒ Object
848 849 850 |
# File 'lib/voruby/votable/1.1/votable.rb', line 848 def ref self.node['ref'] end |
#ref=(r) ⇒ Object
852 853 854 |
# File 'lib/voruby/votable/1.1/votable.rb', line 852 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 # =>
<table id="table1">
<caption>A test table</caption>
<thead>
<tr>
<th>
<div class="field" id="col1">
<div class="name">RA</div>
<div class="ucd">pos.eq.ra;meta.main</div>
<div class="unit">deg</div>
<span class="datatype">float</span>
</div>
</th>
<th>
<div class="field" id="col2">
<div class="name">Dec</div>
<div class="ucd">pos.eq.dec;meta.main</div>
<div class="unit">deg</div>
<span class="datatype">float</span>
</div>
</th>
<th>
<div class="field" id="col3">
<div class="name">Name</div>
<div class="ucd">meta.id;meta.main</div>
<span class="datatype">char</span>
<span class="arraysize">8*</span>
</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>123</td>
<td>456</td>
<td>my_obj1</td>
</tr>
<tr>
<td>789</td>
<td>112</td>
<td>my_obj2</td>
</tr>
<tr>
<td>145</td>
<td>178</td>
<td>my_obj3</td>
</tr>
</tbody>
</table
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 |
# File 'lib/voruby/votable/1.1/votable.rb', line 1026 def to_html builder = Builder::XmlMarkup.new(:indent => 2, :margin => 2) = {} [:id] = self.id if self.id builder.table() { |table| table.(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 |
#ucd ⇒ Object
856 857 858 |
# File 'lib/voruby/votable/1.1/votable.rb', line 856 def ucd self.node['ucd'] end |
#ucd=(u) ⇒ Object
Set the unified content descriptor or UCD.
861 862 863 |
# File 'lib/voruby/votable/1.1/votable.rb', line 861 def ucd=(u) @node['ucd'] = u.to_s end |
#utype ⇒ Object
865 866 867 |
# File 'lib/voruby/votable/1.1/votable.rb', line 865 def utype self.node['utype'] end |
#utype=(u) ⇒ Object
Set the utype (i.e. the role of the column in the context of an external data model).
870 871 872 |
# File 'lib/voruby/votable/1.1/votable.rb', line 870 def utype=(u) @node['utype'] = u.to_s end |