Browse files

Fixed some old crappy code

  • Loading branch information...
1 parent d358cb5 commit 55f94063b6d045bb7e79b1b8e40c384f40853407 @tj tj committed Oct 16, 2009
Showing with 12 additions and 13 deletions.
  1. +12 −13 lib/terminal-table/cell.rb
View
25 lib/terminal-table/cell.rb
@@ -4,6 +4,11 @@ class Table
class Cell
##
+ # Cell width.
+
+ attr_reader :width
+
+ ##
# Cell value.
attr_reader :value
@@ -21,33 +26,27 @@ class Cell
##
# Initialize with _width_ and _options_.
- def initialize width, options = {}
+ def initialize width, options = nil
@width = width
- @alignment = :left
- @colspan = 1
-
- if options.is_a? Hash
- @value = options[:value]
- @alignment = options[:alignment] unless options[:alignment].nil?
- @colspan = options[:colspan] unless options[:colspan].nil?
- else
- @value = options
- end
+ @value, options = options, {} unless Hash === options
+ @value = options.fetch :value, value
+ @alignment = options.fetch :alignment, :left
+ @colspan = options.fetch :colspan, 1
end
##
# Render the cell.
def render
- " #{value.to_s} ".align alignment, @width + 2
+ " #{value} ".align alignment, width + 2
end
alias :to_s :render
##
# Cell length.
def length
- @value.to_s.length + 2
+ value.to_s.length + 2
end
end
end

0 comments on commit 55f9406

Please sign in to comment.