Skip to content

Commit

Permalink
Inline docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Oct 16, 2009
1 parent e8469a1 commit d358cb5
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions lib/terminal-table/cell.rb
Expand Up @@ -3,27 +3,49 @@ module Terminal
class Table
class Cell

attr_accessor :value, :alignment, :colspan
##
# Cell value.

def initialize width, params
attr_reader :value

##
# Cell alignment.

attr_reader :alignment

##
# Column span.

attr_reader :colspan

##
# Initialize with _width_ and _options_.

def initialize width, options = {}
@width = width
@alignment = :left
@colspan = 1

if params.is_a? Hash
@value = params[:value]
@alignment = params[:alignment] unless params[:alignment].nil?
@colspan = params[:colspan] unless params[:colspan].nil?
if options.is_a? Hash
@value = options[:value]
@alignment = options[:alignment] unless options[:alignment].nil?
@colspan = options[:colspan] unless options[:colspan].nil?
else
@value = params
@value = options
end
end

##
# Render the cell.

def render
" #{value.to_s} ".align alignment, @width + 2
end
alias :to_s :render

##
# Cell length.

def length
@value.to_s.length + 2
end
Expand Down

0 comments on commit d358cb5

Please sign in to comment.