Class: VORuby::VOTable::V1_1::Td
- Inherits:
-
Base
- Object
- XML::Object::Base
- Base
- VORuby::VOTable::V1_1::Td
- Includes:
- Castable
- Defined in:
- lib/voruby/votable/1.1/votable.rb
Overview
A data element in a table row.
Constant Summary collapse
- ELEMENT_NAME =
'TD'
Instance Attribute Summary
Attributes inherited from XML::Object::Base
Instance Method Summary collapse
- #encoding ⇒ Object
- #encoding=(e) ⇒ Object
-
#field ⇒ Object
Retrieve the Field associated with this column.
-
#initialize(defn = nil) ⇒ Td
constructor
Create a new data element.
-
#text ⇒ Object
Retrieve the value of the data element as text.
-
#text=(txt) ⇒ Object
Set the value of the data element as text.
-
#to_html ⇒ Object
Convert a column to HTML.
-
#value ⇒ Object
Retrieve the value of the data element as an appropriate object (or list of objects), according to the datatype and arraysize of the Field corresponding to this column.
-
#value=(v) ⇒ Object
Set the value of the data element.
Methods included from Castable
#as_obj, #as_string, #cast, #convert_to_s
Methods inherited from Base
#==, element_name, #get_element, #xpath_for
Methods inherited from XML::Object::Base
#==, element_name, from_file, #to_s
Constructor Details
Instance Method Details
#encoding ⇒ Object
2034 2035 2036 |
# File 'lib/voruby/votable/1.1/votable.rb', line 2034 def encoding self.node['encoding'] end |
#encoding=(e) ⇒ Object
2038 2039 2040 |
# File 'lib/voruby/votable/1.1/votable.rb', line 2038 def encoding=(e) @node['encoding'] = e.to_s end |
#field ⇒ Object
Retrieve the Field associated with this column.
2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 |
# File 'lib/voruby/votable/1.1/votable.rb', line 2070 def field node_path = self.node.path # use the xpath to determine the position pos = (node_path =~ /TD\[\d+\]$/) ? node_path.split('/').last.match(/TD\[(\d+)\]$/)[1] : '1' field_node = self.node.find_first("../../../../*[local-name()='FIELD'][#{pos}]") field_node ? Field.new(field_node) : raise("Unable to associate a FIELD with this TD") end |
#text ⇒ Object
Retrieve the value of the data element as text.
2043 2044 2045 |
# File 'lib/voruby/votable/1.1/votable.rb', line 2043 def text self.node.content end |
#text=(txt) ⇒ Object
Set the value of the data element as text.
2048 2049 2050 |
# File 'lib/voruby/votable/1.1/votable.rb', line 2048 def text=(txt) @node.content = txt.to_s end |
#to_html ⇒ Object
2085 2086 2087 2088 2089 |
# File 'lib/voruby/votable/1.1/votable.rb', line 2085 def to_html builder = Builder::XmlMarkup.new(:indent => 2, :margin => 5) builder.td(self.text) end |
#value ⇒ Object
Retrieve the value of the data element as an appropriate object (or list of objects), according to the datatype and arraysize of the Field corresponding to this column. See Castable#as_obj for more details.
2056 2057 2058 2059 |
# File 'lib/voruby/votable/1.1/votable.rb', line 2056 def value cfield = self.field as_obj(self.text, cfield.datatype, cfield.arraysize) end |
#value=(v) ⇒ Object
Set the value of the data element. An attempt is made to convert native ruby types using the datatype and arraysize parameters of the associated Field.
2064 2065 2066 2067 |
# File 'lib/voruby/votable/1.1/votable.rb', line 2064 def value=(v) cfield = self.field self.text = as_string(v, cfield.datatype, cfield.arraysize) end |