Permalink
Browse files

add alignment style option

  • Loading branch information...
1 parent d4e7636 commit 36d4bab3072ed440eb87de0bd16ed01129012232 cowardx committed Apr 30, 2012
Showing with 23 additions and 3 deletions.
  1. +1 −1 lib/terminal-table/cell.rb
  2. +3 −2 lib/terminal-table/style.rb
  3. +19 −0 spec/table_spec.rb
View
2 lib/terminal-table/cell.rb
@@ -36,7 +36,7 @@ def alignment?
end
def alignment
- @alignment || :left
+ @alignment || @table.style.alignment || :left
end
def alignment=(val)
View
5 lib/terminal-table/style.rb
@@ -26,7 +26,7 @@ class Style
@@defaults = {
:border_x => "-", :border_y => "|", :border_i => "+",
:padding_left => 1, :padding_right => 1,
- :width => nil
+ :width => nil, :alignment => nil
}
attr_accessor :border_x
@@ -37,6 +37,7 @@ class Style
attr_accessor :padding_right
attr_accessor :width
+ attr_accessor :alignment
def initialize options = {}
@@ -58,4 +59,4 @@ def defaults= options
end
end
end
-end
+end
View
19 spec/table_spec.rb
@@ -137,6 +137,25 @@ module Terminal
EOF
end
+
+ it "should render default alignment properly" do
+ @table.headings = ['Char', 'Num']
+ @table << ['a', 1]
+ @table << ['b', 2]
+ @table << ['c', 3]
+ @table.style.width = 21
+ @table.style.alignment = :right
+ @table.render.should == <<-EOF.deindent
+ +---------+---------+
+ | Char | Num |
+ +---------+---------+
+ | a | 1 |
+ | b | 2 |
+ | c | 3 |
+ +---------+---------+
+ EOF
+ end
+
it "should render width properly" do
@table.headings = ['Char', 'Num']
@table << ['a', 1]

0 comments on commit 36d4bab

Please sign in to comment.