Permalink
Browse files

Free table headers for you lazies out there, and general refactoring

git-svn-id: http://stonecode.svnrepository.com/svn/ruport/trunk@591 bb2e8eb0-7117-0410-aac4-c024b40ed5f7
  • Loading branch information...
1 parent 63cbfb2 commit ddd4ce23b935853d12495953e84f05d728342b3d sandal committed Mar 8, 2007
Showing with 54 additions and 4 deletions.
  1. +6 −0 lib/ruport/data/grouping.rb
  2. +10 −0 lib/ruport/data/table.rb
  3. +3 −2 lib/ruport/format/html.rb
  4. +2 −2 lib/ruport/format/text.rb
  5. +25 −0 test/test_grouping.rb
  6. +8 −0 test/test_table.rb
@@ -45,6 +45,12 @@ def dup
return obj
end
+ def eql?(other)
+ name.eql?(other.name) && super
+ end
+
+ alias_method :==, :eql?
+
protected
def name=(value) #:nodoc:
View
@@ -33,6 +33,9 @@ def as(*args)
# Converts a <tt>Collection</tt> object to a <tt>Data::Table</tt>.
def to_table(options={})
+ if respond_to? :column_names
+ options = { :column_names => column_names }.merge(options)
+ end
Table.new({:data => data.map { |r| r.to_a }}.merge(options))
end
@@ -548,6 +551,13 @@ def dup
def to_s
as(:text)
end
+
+
+ def to_group(name)
+ Group.new( :data => data,
+ :column_names => column_names,
+ :name => name )
+ end
# NOTE: does not respect tainted status
alias_method :clone, :dup
@@ -49,8 +49,9 @@ def build_group_header
# Table renderer.
#
def build_group_body
- Ruport::Renderer::Table.render(:html, :data => data, :io => output,
- :show_table_headers => show_group_headers)
+ data.to_table.as(:html, :io => output,
+ :show_table_headers => show_group_headers )
+
end
# Renders individual rows for the table
@@ -63,8 +63,8 @@ def build_group_header
end
def build_group_body
- Ruport::Renderer::Table.render(:text, :data => data, :io => output,
- :show_table_headers => show_group_headers)
+ data.to_table.as( :text, :io => output,
+ :show_table_headers => show_group_headers)
end
def build_row
View
@@ -34,5 +34,30 @@ def test_group_as
assert_equal(13,group.to_html.to_a.length)
end
+ def test_eql
+ group = Ruport::Data::Group.new(:name => 'test',
+ :data => [%w[ruport is sexy]],
+ :column_names => %w[software isnt sexy])
+ table = [%w[ruport is sexy]].to_table(%w[software isnt sexy])
+
+ group2 = Ruport::Data::Group.new(:name => 'test',
+ :data => [%w[ruport is sexy]],
+ :column_names => %w[software isnt sexy])
+
+ assert_raises(NoMethodError) { group == table }
+ assert_equal group, group2
+ assert_equal group, group.dup
+ end
+
+ def test_to_table
+ group = Ruport::Data::Group.new(:name => 'test',
+ :data => [%w[Ruport Is Sexy]],
+ :column_names => %w[Software Isnt Sexy])
+ table = [%w[Ruport Is Sexy]].to_table(%w[Software Isnt Sexy])
+
+ assert_equal table, group.to_table
+
+ end
+
end
View
@@ -51,6 +51,14 @@ def test_column
assert_equal [1,2,3,4], a.column(0)
end
+
+ def test_to_group
+ a =[[1,2,3],[4,5,6]].to_table(%w[a b c]).to_group("Packrats")
+ b = Ruport::Data::Group.new( :data => [[1,2,3],[4,5,6]],
+ :column_names => %w[a b c],
+ :name => "Packrats" )
+ assert_equal a,b
+ end
def test_set_column_names
a = [[1,2,3],[4,5,6]].to_table

0 comments on commit ddd4ce2

Please sign in to comment.