Class: TTY::Table::Field Private
- Inherits:
-
Object
- Object
- TTY::Table::Field
- Includes:
- Equatable
- Defined in:
- lib/tty/table/field.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A class that represents a unique element in a table.
Used internally by Row to define internal structure.
Instance Attribute Summary collapse
- #align ⇒ Object readonly private
-
#colspan ⇒ Object
readonly
private
Number of columns this field spans.
-
#name ⇒ Object
readonly
The name for the value.
-
#rowspan ⇒ Object
readonly
private
Number of rows this field spans.
-
#value ⇒ Object
The value inside the field.
-
#width ⇒ Object
readonly
The field value width.
Instance Method Summary collapse
- #chars ⇒ Object private
-
#extract_options(value) ⇒ Object
private
Extract options and set value.
-
#height ⇒ Integer
Extract the number of lines this value spans.
-
#initialize(value) ⇒ Field
constructor
private
Initialize a Field.
-
#length ⇒ Integer
If the string contains unescaped new lines then the longest token deterimines the actual field length.
-
#lines ⇒ Array[String]
Return number of lines this value spans.
-
#render ⇒ Object
Render value inside this field box.
-
#to_s ⇒ Object
Return field value.
- #value_height ⇒ Object private
-
#value_width ⇒ Object
Return the width this field would normally have bar other contraints.
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
57 58 59 60 61 62 63 |
# File 'lib/tty/table/field.rb', line 57 def initialize(value) = (value) @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)
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.
39 40 41 |
# File 'lib/tty/table/field.rb', line 39 def align @align end |
#colspan ⇒ Object (readonly)
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.
Number of columns this field spans. Defaults to 1.
33 34 35 |
# File 'lib/tty/table/field.rb', line 33 def colspan @colspan end |
#name ⇒ Object (readonly)
The name for the value
21 22 23 |
# File 'lib/tty/table/field.rb', line 21 def name @name end |
#rowspan ⇒ Object (readonly)
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.
Number of rows this field spans. Defaults to 1.
37 38 39 |
# File 'lib/tty/table/field.rb', line 37 def rowspan @rowspan end |
#value ⇒ Object
The value inside the field
16 17 18 |
# File 'lib/tty/table/field.rb', line 16 def value @value end |
#width ⇒ Object (readonly)
The field value width
29 30 31 |
# File 'lib/tty/table/field.rb', line 29 def width @width end |
Instance Method Details
#chars ⇒ Object
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.
121 122 123 |
# File 'lib/tty/table/field.rb', line 121 def chars value.chars end |
#extract_options(value) ⇒ Object
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.
Extract options and set value
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tty/table/field.rb', line 68 def (value) if value.class <= Hash = value @value = .fetch(:value) else @value = value = {} end end |
#height ⇒ Integer
Extract the number of lines this value spans
117 118 119 |
# File 'lib/tty/table/field.rb', line 117 def height lines.size end |
#length ⇒ Integer
If the string contains unescaped new lines then the longest token deterimines the actual field length.
108 109 110 |
# File 'lib/tty/table/field.rb', line 108 def length (lines.max_by(&:length) || '').size end |
#lines ⇒ Array[String]
Return number of lines this value spans.
A distinction is being made between escaped and non-escaped strings.
97 98 99 100 |
# File 'lib/tty/table/field.rb', line 97 def lines escaped = value.to_s.scan(/(\\n|\\t|\\r)/) escaped.empty? ? value.to_s.split(/\n/, -1) : [value.to_s] end |
#render ⇒ Object
Render value inside this field box
128 129 |
# File 'lib/tty/table/field.rb', line 128 def render end |
#to_s ⇒ Object
Return field value
134 135 136 |
# File 'lib/tty/table/field.rb', line 134 def to_s value end |
#value_height ⇒ Object
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.
86 87 88 |
# File 'lib/tty/table/field.rb', line 86 def value_height @height end |
#value_width ⇒ Object
Return the width this field would normally have bar other contraints
82 83 84 |
# File 'lib/tty/table/field.rb', line 82 def value_width @width end |