Class: Termtable::Cell
- Inherits:
-
Object
- Object
- Termtable::Cell
- Defined in:
- lib/termtable/cell.rb
Instance Attribute Summary collapse
-
#alignment ⇒ Object
Returns the value of attribute alignment.
-
#max_column_size ⇒ Object
Returns the value of attribute max_column_size.
-
#padding ⇒ Object
Returns the value of attribute padding.
-
#total_padding ⇒ Object
Returns the value of attribute total_padding.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #expand? ⇒ Boolean
-
#initialize(value) ⇒ Cell
constructor
A new instance of Cell.
- #left_padding ⇒ Object
- #render ⇒ Object
- #right_padding ⇒ Object
Constructor Details
#initialize(value) ⇒ Cell
Returns a new instance of Cell.
9 10 11 |
# File 'lib/termtable/cell.rb', line 9 def initialize(value) @value = value.to_s end |
Instance Attribute Details
#alignment ⇒ Object
Returns the value of attribute alignment.
4 5 6 |
# File 'lib/termtable/cell.rb', line 4 def alignment @alignment end |
#max_column_size ⇒ Object
Returns the value of attribute max_column_size.
4 5 6 |
# File 'lib/termtable/cell.rb', line 4 def max_column_size @max_column_size end |
#padding ⇒ Object
Returns the value of attribute padding.
4 5 6 |
# File 'lib/termtable/cell.rb', line 4 def padding @padding end |
#total_padding ⇒ Object
Returns the value of attribute total_padding.
4 5 6 |
# File 'lib/termtable/cell.rb', line 4 def total_padding @total_padding end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/termtable/cell.rb', line 3 def value @value end |
Instance Method Details
#expand? ⇒ Boolean
13 14 15 |
# File 'lib/termtable/cell.rb', line 13 def max_column_size != value.to_s.size + total_padding end |
#left_padding ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/termtable/cell.rb', line 17 def left_padding count = case alignment when 'right' ? max_column_size - value.to_s.size : padding when 'center' ? (max_column_size - value.to_s.size) / 2 : padding else 0 end ' ' * count end |
#render ⇒ Object
47 48 49 |
# File 'lib/termtable/cell.rb', line 47 def render "#{left_padding}#{value}#{right_padding}" end |
#right_padding ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/termtable/cell.rb', line 29 def right_padding count = case alignment when 'right' 0 when 'center' if && max_column_size.even? (max_column_size - value.to_s.size) / 2 elsif && max_column_size.odd? (max_column_size - value.to_s.size) / 2 + 1 else padding end else ? max_column_size - value.to_s.size : padding end ' ' * count end |