Class: TTY::Table::Padder Private
- Inherits:
-
Object
- Object
- TTY::Table::Padder
- Includes:
- Equatable
- Defined in:
- lib/tty/table/padder.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 responsible for processing table field padding
Used internally by Renderer
Instance Attribute Summary collapse
-
#padding ⇒ Array[Integer]
readonly
private
Padding for the table cells.
Class Method Summary collapse
-
.convert_to_ary(value) ⇒ Array[Integer]
private
Convert value to 4 element array.
-
.parse(value = nil) ⇒ TTY::Padder
Parse padding options.
Instance Method Summary collapse
-
#bottom ⇒ Integer
Bottom padding.
-
#bottom=(value) ⇒ nil
Set bottom padding.
-
#empty? ⇒ Boolean
Check if padding is set.
-
#horizontal? ⇒ Boolean
Check if horizontal padding is applied.
-
#initialize(padding) ⇒ Padder
constructor
Initialize a Padder.
-
#left ⇒ Integer
Left padding.
-
#left=(value) ⇒ nil
Set left padding.
-
#right ⇒ Integer
Right padding.
-
#right=(value) ⇒ Object
Set right padding.
-
#to_s ⇒ String
String represenation of this padder with padding values.
-
#top ⇒ Integer
Top padding.
-
#top=(value) ⇒ nil
Set top padding.
-
#vertical? ⇒ Boolean
Check if vertical padding is applied.
Constructor Details
#initialize(padding) ⇒ Padder
Initialize a Padder
21 22 23 |
# File 'lib/tty/table/padder.rb', line 21 def initialize(padding) @padding = padding end |
Instance Attribute Details
#padding ⇒ Array[Integer] (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.
Padding for the table cells
16 17 18 |
# File 'lib/tty/table/padder.rb', line 16 def padding @padding end |
Class Method Details
.convert_to_ary(value) ⇒ Array[Integer]
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.
Convert value to 4 element array
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tty/table/padder.rb', line 51 def self.convert_to_ary(value) if value.class <= Numeric [value, value, value, value] elsif value.nil? [] elsif value.size == 2 [value[0], value[1], value[0], value[1]] elsif value.size == 4 value else fail ArgumentError, 'Wrong :padding parameter, must be an array' end end |
.parse(value = nil) ⇒ TTY::Padder
Parse padding options
Turn possible values into 4 element array
39 40 41 42 43 |
# File 'lib/tty/table/padder.rb', line 39 def self.parse(value = nil) return value if value.is_a?(self) new(convert_to_ary(value)) end |
Instance Method Details
#bottom ⇒ Integer
Bottom padding
108 109 110 |
# File 'lib/tty/table/padder.rb', line 108 def bottom @padding[2].to_i end |
#bottom=(value) ⇒ nil
Set bottom padding
119 120 121 |
# File 'lib/tty/table/padder.rb', line 119 def bottom=(value) @padding[2] = value end |
#empty? ⇒ Boolean
Check if padding is set
148 149 150 |
# File 'lib/tty/table/padder.rb', line 148 def empty? padding.empty? end |
#horizontal? ⇒ Boolean
Check if horizontal padding is applied
166 167 168 |
# File 'lib/tty/table/padder.rb', line 166 def horizontal? left.nonzero? || right.nonzero? end |
#left ⇒ Integer
Left padding
128 129 130 |
# File 'lib/tty/table/padder.rb', line 128 def left @padding[3].to_i end |
#left=(value) ⇒ nil
Set left padding
139 140 141 |
# File 'lib/tty/table/padder.rb', line 139 def left=(value) @padding[3] = value end |
#right ⇒ Integer
Right padding
90 91 92 |
# File 'lib/tty/table/padder.rb', line 90 def right @padding[1].to_i end |
#right=(value) ⇒ Object
Set right padding
99 100 101 |
# File 'lib/tty/table/padder.rb', line 99 def right=(value) @padding[1] = value end |
#to_s ⇒ String
String represenation of this padder with padding values
175 176 177 |
# File 'lib/tty/table/padder.rb', line 175 def to_s inspect end |
#top ⇒ Integer
Top padding
70 71 72 |
# File 'lib/tty/table/padder.rb', line 70 def top @padding[0].to_i end |
#top=(value) ⇒ nil
Set top padding
81 82 83 |
# File 'lib/tty/table/padder.rb', line 81 def top=(value) @padding[0] = value end |
#vertical? ⇒ Boolean
Check if vertical padding is applied
157 158 159 |
# File 'lib/tty/table/padder.rb', line 157 def vertical? top.nonzero? || bottom.nonzero? end |