Class: TTY::Table::Padder Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#paddingArray[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

Returns:

  • (Array[Integer])


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

Returns:

  • (Array[Integer])

    the 4 element padding 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

Examples:

padder = TTY::Table::Padder.parse(5)
padder.padding # => [5, 5, 5, 5]

Parameters:

  • value (Object) (defaults to: nil)

Returns:

  • (TTY::Padder)

    the new padder with padding values



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

#bottomInteger

Bottom padding

Returns:

  • (Integer)


108
109
110
# File 'lib/tty/table/padder.rb', line 108

def bottom
  @padding[2].to_i
end

#bottom=(value) ⇒ nil

Set bottom padding

Parameters:

  • value (Integer)

Returns:

  • (nil)


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

Returns:

  • (Boolean)


148
149
150
# File 'lib/tty/table/padder.rb', line 148

def empty?
  padding.empty?
end

#horizontal?Boolean

Check if horizontal padding is applied

Returns:

  • (Boolean)


166
167
168
# File 'lib/tty/table/padder.rb', line 166

def horizontal?
  left.nonzero? || right.nonzero?
end

#leftInteger

Left padding

Returns:

  • (Integer)


128
129
130
# File 'lib/tty/table/padder.rb', line 128

def left
  @padding[3].to_i
end

#left=(value) ⇒ nil

Set left padding

Parameters:

  • value (Integer)

Returns:

  • (nil)


139
140
141
# File 'lib/tty/table/padder.rb', line 139

def left=(value)
  @padding[3] = value
end

#rightInteger

Right padding

Returns:

  • (Integer)


90
91
92
# File 'lib/tty/table/padder.rb', line 90

def right
  @padding[1].to_i
end

#right=(value) ⇒ Object

Set right padding

Parameters:

  • val (Integer)


99
100
101
# File 'lib/tty/table/padder.rb', line 99

def right=(value)
  @padding[1] = value
end

#to_sString

String represenation of this padder with padding values

Returns:

  • (String)


175
176
177
# File 'lib/tty/table/padder.rb', line 175

def to_s
  inspect
end

#topInteger

Top padding

Returns:

  • (Integer)


70
71
72
# File 'lib/tty/table/padder.rb', line 70

def top
  @padding[0].to_i
end

#top=(value) ⇒ nil

Set top padding

Parameters:

  • val (Integer)

Returns:

  • (nil)


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

Returns:

  • (Boolean)


157
158
159
# File 'lib/tty/table/padder.rb', line 157

def vertical?
  top.nonzero? || bottom.nonzero?
end