lib/celerity/elements/table.rb in celerity-0.0.2 vs lib/celerity/elements/table.rb in celerity-0.0.3
- old
+ new
@@ -1,12 +1,14 @@
module Celerity
class Table < Element
+ include Enumerable # specs for this?
include Container
+
TAGS = [ Identifier.new('table') ]
ATTRIBUTES = BASE_ATTRIBUTES | [:summary, :width, :border, :frame, :rules, :cellspacing, :cellpadding, :align, :bgcolor]
- DEFAULT_HOW = :name
+ DEFAULT_HOW = :id
def locate
super
if @object # cant call assert_exists here, as an exists? method call will fail
@rows = @object.getRows
@@ -29,11 +31,11 @@
return TableCells.new(self, :object, @cells)
end
def each
assert_exists
- 0.upto(@object.getRowCount-1) { |index| yield TableRow.new(self, :object, @rows[index]) }
+ @rows.each { |row| yield TableRow.new(self, :object, row) }
end
def [](index)
assert_exists
return TableRow.new(self, :object, @rows[index-1])
@@ -47,13 +49,12 @@
def column_count(index = 1)
assert_exists
@object.getRow(index-1).getCells.length
end
- # This method returns the table as a 2 dimensional array. Dont expect too much if there are nested tables, colspan etc.
+ # This method returns the table as a 2 dimensional array.
# Raises an UnknownObjectException if the table doesn't exist.
- # http://www.w3.org/TR/html4/struct/tables.html
def to_a
assert_exists
y = []
table_rows = @object.getRows
for table_row in table_rows
@@ -64,31 +65,16 @@
y << x
end
return y
end
- def table_body(index = 1)
- return @object.getBodies.get(index)
- end
- private :table_body
-
- def body(how, what)
- assert_exists
- return TableBody.new(@container, how, what)
- end
-
- def bodies
- assert_exists
- return TableBodies.new(self)
- end
-
def column_values(columnnumber)
- return (1..row_count).collect { |index| self[index][columnnumber].text }
+ (1..row_count).collect { |index| self[index][columnnumber].text }
end
def row_values(rownumber)
- return (1..column_count(rownumber)).collect { |index| self[rownumber][index].text }
+ (1..column_count(rownumber)).collect { |index| self[rownumber][index].text }
end
-
+
end
end
\ No newline at end of file