Class: VORuby::VOTable::V1_0::Tr

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

Overview

A row of data in a TableData.

Constant Summary collapse

ELEMENT_NAME =
'TR'

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) ⇒ Tr

Create a new row of data.

tr = Tr.new(:tds => [Td.new()])


1693
1694
1695
# File 'lib/voruby/votable/1.0/votable.rb', line 1693

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

Instance Method Details

#tdsObject

Retrieve the table data elements in the row. Returns a HomogeneousNodeList.



1699
1700
1701
# File 'lib/voruby/votable/1.0/votable.rb', line 1699

def tds
  HomogeneousNodeList.new(self.node, xpath_for(Td), Td)
end

#tds=(columns) ⇒ Object

Set the data elements of the row.

tr.tds = [Td.new(), ...]


1705
1706
1707
# File 'lib/voruby/votable/1.0/votable.rb', line 1705

def tds=(columns)
  self.tds.replace(columns)
end

#to_htmlObject

Convert a table row to HTML.

tr = Tr.new(:tds => [Td.new(:text => 'hello'), Td.new(:text => 'world')])
puts tr.to_html # => 
  <tr>
    <td>hello</td>
    <td>world</td>
  </tr>


1716
1717
1718
1719
1720
1721
1722
1723
1724
# File 'lib/voruby/votable/1.0/votable.rb', line 1716

def to_html
  builder = Builder::XmlMarkup.new(:indent => 2, :margin => 4)
  
  builder.tr { |tr|
    self.tds.each do |column|
      tr << column.to_html
    end
  }
end