Skip to content
This repository
Browse code

add alignment style option

  • Loading branch information...
commit 36d4bab3072ed440eb87de0bd16ed01129012232 1 parent d4e7636
cowardx authored
2  lib/terminal-table/cell.rb
@@ -36,7 +36,7 @@ def alignment?
36 36 end
37 37
38 38 def alignment
39   - @alignment || :left
  39 + @alignment || @table.style.alignment || :left
40 40 end
41 41
42 42 def alignment=(val)
5 lib/terminal-table/style.rb
@@ -26,7 +26,7 @@ class Style
26 26 @@defaults = {
27 27 :border_x => "-", :border_y => "|", :border_i => "+",
28 28 :padding_left => 1, :padding_right => 1,
29   - :width => nil
  29 + :width => nil, :alignment => nil
30 30 }
31 31
32 32 attr_accessor :border_x
@@ -37,6 +37,7 @@ class Style
37 37 attr_accessor :padding_right
38 38
39 39 attr_accessor :width
  40 + attr_accessor :alignment
40 41
41 42
42 43 def initialize options = {}
@@ -58,4 +59,4 @@ def defaults= options
58 59 end
59 60 end
60 61 end
61   -end
  62 +end
19 spec/table_spec.rb
@@ -137,6 +137,25 @@ module Terminal
137 137 EOF
138 138 end
139 139
  140 +
  141 + it "should render default alignment properly" do
  142 + @table.headings = ['Char', 'Num']
  143 + @table << ['a', 1]
  144 + @table << ['b', 2]
  145 + @table << ['c', 3]
  146 + @table.style.width = 21
  147 + @table.style.alignment = :right
  148 + @table.render.should == <<-EOF.deindent
  149 + +---------+---------+
  150 + | Char | Num |
  151 + +---------+---------+
  152 + | a | 1 |
  153 + | b | 2 |
  154 + | c | 3 |
  155 + +---------+---------+
  156 + EOF
  157 + end
  158 +
140 159 it "should render width properly" do
141 160 @table.headings = ['Char', 'Num']
142 161 @table << ['a', 1]

0 comments on commit 36d4bab

Please sign in to comment.
Something went wrong with that request. Please try again.