Skip to content

Commit

Permalink
Refactored #number_of_columns
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Mar 14, 2009
1 parent e504f6d commit 43eff59
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 2 additions & 5 deletions lib/terminal-table/table.rb
Expand Up @@ -125,11 +125,8 @@ def length_of_column n
# Return total number of columns available.

def number_of_columns
if rows[0]
rows[0].length
else
raise Error, 'Your table needs some rows'
end
return rows.first.length unless rows.empty?
raise Error, 'your table needs some rows.'
end

##
Expand Down
4 changes: 3 additions & 1 deletion lib/terminal-table/version.rb
@@ -1,4 +1,6 @@

module Terminal
VERSION = '1.0.4'
class Table
VERSION = '1.0.4'
end
end
4 changes: 4 additions & 0 deletions spec/table_spec.rb
Expand Up @@ -59,6 +59,10 @@
@table << ['a', 1]
@table.seperator.should == '+------+-----+'
end

it "should bitch and complain when you have no rows" do
lambda { @table.render }.should raise_error(Terminal::Table::Error)
end

it "should render properly" do
@table.headings = ['Char', 'Num']
Expand Down

0 comments on commit 43eff59

Please sign in to comment.