Changeset 384

Show
Ignore:
Timestamp:
12/21/06 23:39:19 (2 years ago)
Author:
sandal
Message:

Fix for #119

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/ruport/format/text.rb

    r382 r384  
    2323          line = Array.new 
    2424          r.each_with_index { |f,i| 
    25             line << f.to_s.center(layout.max_col_width[i]) 
     25            if layout.alignment.eql? :center 
     26              line << f.to_s.center(layout.max_col_width[i]) 
     27            else 
     28              align = f.is_a?(Numeric) ? :rjust : :ljust 
     29              line << f.to_s.send(align, layout.max_col_width[i]) 
     30            end 
    2631          } 
    2732          s += "| #{line.join(' | ')} |\n" 
  • trunk/test/test_text_table.rb

    r372 r384  
    1313  end 
    1414 
    15   #def test_max_col_width 
    16   #  a = Format.table_object :plugin => :text, :data => [[1,2],[300,4]] 
    17   #  a.active_plugin.calculate_max_col_widths 
    18   #  assert_equal(3,a.active_plugin.max_col_width[0]) 
    19   #  assert_equal(1,a.active_plugin.max_col_width[1]) 
    20  
    21   #  a.data = [[1,2],[300,4]].to_table(:column_names => %w[a ba]) 
    22   #  a.active_plugin.calculate_max_col_widths 
    23   #  assert_equal(3,a.active_plugin.max_col_width[0]) 
    24   #  assert_equal(2,a.active_plugin.max_col_width[1]) 
    25  
    26   #  a.data = [[1,2],[3,40000]].to_table(:column_names => %w[foo bazz]) 
    27   #  a.active_plugin.calculate_max_col_widths 
    28   #  assert_equal(3,a.active_plugin.max_col_width[0]) 
    29   #  assert_equal(5,a.active_plugin.max_col_width[1])   
    30   #end 
    31  
    32   #def test_hr 
    33   #  a = Format.table_object :plugin => :text, :data => [[1,2],[300,4]] 
    34   #  a.active_plugin.calculate_max_col_widths 
    35   #  assert_equal("+---------+\n",a.active_plugin.hr) 
    36  
    37  
    38   #  a.data = [[1,2],[3,40000]].to_table(:column_names => %w[foo bazz]) 
    39   #  a.active_plugin.calculate_max_col_widths 
    40   #  assert_equal "+-------------+\n", a.active_plugin.hr 
    41      
    42   #end 
    4315 
    4416  def test_centering 
     
    4618 
    4719    a = [[1,2],[300,4]].to_table 
    48     assert_equal("#{tf}|  1  | 2 |\n| 300 | 4 |\n#{tf}",a.to_text) 
     20    assert_equal( "#{tf}|  1  | 2 |\n| 300 | 4 |\n#{tf}", 
     21                  a.as(:text) { |e| e.layout.alignment = :center }) 
    4922 
    5023    tf = "+------------+\n" 
    5124    a.column_names = %w[a bark] 
    5225    assert_equal("#{tf}|  a  | bark |\n#{tf}|  1  |  2   |\n"+ 
    53                  "| 300 |  4   |\n#{tf}",a.to_text) 
     26                 "| 300 |  4   |\n#{tf}", 
     27                  a.as(:text) { |e| e.layout.alignment = :center }) 
    5428     
     29  end 
     30 
     31  def test_justified 
     32    tf = "+----------+\n" 
     33    a = [[1,'Z'],[300,'BB']].to_table 
     34    assert_equal "#{tf}|   1 | Z  |\n| 300 | BB |\n#{tf}", a.to_s 
    5535  end 
    5636 
     
    6040    } 
    6141 
    62     assert_equal("+------->>\n|  1 | >>\n| 300 | >>\n+------->>\n",a) 
     42    assert_equal("+------->>\n|  1 | >>\n| 300 | >>\n+------->>\n",a) 
    6343  end 
    6444