Class: TTY::Table::Field
- Inherits:
-
Object
- Object
- TTY::Table::Field
- Includes:
- Equatable
- Defined in:
- lib/tty/table/field.rb
Overview
A class that represents a unique element in a table.
Instance Attribute Summary collapse
-
#align ⇒ Object
readonly
Returns the value of attribute align.
-
#colspan ⇒ Object
readonly
Number of columns this field spans.
-
#rowspan ⇒ Object
readonly
Number of rows this field spans.
-
#value ⇒ Object
The value inside the field.
-
#width ⇒ Object
readonly
The field value width.
Attributes included from Equatable
Instance Method Summary collapse
- #height ⇒ Object
-
#initialize(value) ⇒ Field
constructor
private
Initialize a Field.
-
#lines ⇒ Object
Return number of lines this value spans.
- #longest_line ⇒ Object
-
#render ⇒ Object
Render value inside this field box.
-
#to_s ⇒ Object
Return field value.
- #value_height ⇒ Object
-
#value_width ⇒ Object
Return the width this field would normally have bar other contraints.
Methods included from Equatable
#attr_reader, included, #inherited
Constructor Details
#initialize(value) ⇒ Field
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a Field
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tty/table/field.rb', line 47 def initialize(value) if value.class <= Hash = value @value = .fetch(:value) else @value = value = {} end @width = .fetch(:width) { @value.to_s.size } @align = .fetch(:align) { nil } @colspan = .fetch(:colspan) { 1 } @rowspan = .fetch(:rowspan) { 1 } end |
Instance Attribute Details
#align ⇒ Object (readonly)
Returns the value of attribute align.
31 32 33 |
# File 'lib/tty/table/field.rb', line 31 def align @align end |
#colspan ⇒ Object (readonly)
Number of columns this field spans. Defaults to 1.
25 26 27 |
# File 'lib/tty/table/field.rb', line 25 def colspan @colspan end |
#rowspan ⇒ Object (readonly)
Number of rows this field spans. Defaults to 1.
29 30 31 |
# File 'lib/tty/table/field.rb', line 29 def rowspan @rowspan end |
#value ⇒ Object
The value inside the field
13 14 15 |
# File 'lib/tty/table/field.rb', line 13 def value @value end |
#width ⇒ Object (readonly)
The field value width
21 22 23 |
# File 'lib/tty/table/field.rb', line 21 def width @width end |
Instance Method Details
#height ⇒ Object
72 73 74 |
# File 'lib/tty/table/field.rb', line 72 def height lines.size end |
#lines ⇒ Object
Return number of lines this value spans
78 79 80 |
# File 'lib/tty/table/field.rb', line 78 def lines value.to_s.split(/\n/) end |
#longest_line ⇒ Object
82 83 84 |
# File 'lib/tty/table/field.rb', line 82 def longest_line lines.max_by(&:length).size end |
#render ⇒ Object
Render value inside this field box
89 90 |
# File 'lib/tty/table/field.rb', line 89 def render end |
#to_s ⇒ Object
Return field value
95 96 97 |
# File 'lib/tty/table/field.rb', line 95 def to_s value end |
#value_height ⇒ Object
68 69 70 |
# File 'lib/tty/table/field.rb', line 68 def value_height @height end |
#value_width ⇒ Object
Return the width this field would normally have bar other contraints
64 65 66 |
# File 'lib/tty/table/field.rb', line 64 def value_width @width end |