Class: Strings::Padder Private
- Inherits:
-
Object
- Object
- Strings::Padder
- Defined in:
- lib/strings/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 parsing padding value
Used internally by Pad
Constant Summary collapse
- ParseError =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Class.new(ArgumentError)
Instance Attribute Summary collapse
-
#padding ⇒ Array[Integer]
readonly
private
Padding.
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.
-
#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.
Constructor Details
#initialize(padding) ⇒ Padder
Initialize a Padder
60 61 62 |
# File 'lib/strings/padder.rb', line 60 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
55 56 57 |
# File 'lib/strings/padder.rb', line 55 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
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/strings/padder.rb', line 38 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 raise ParseError, "Wrong :padding parameter, must be an array" end end |
.parse(value = nil) ⇒ TTY::Padder
Parse padding options
Turn possible values into 4 element array
26 27 28 29 30 |
# File 'lib/strings/padder.rb', line 26 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
107 108 109 |
# File 'lib/strings/padder.rb', line 107 def bottom @padding[2].to_i end |
#bottom=(value) ⇒ nil
Set bottom padding
118 119 120 |
# File 'lib/strings/padder.rb', line 118 def bottom=(value) @padding[2] = value end |
#empty? ⇒ Boolean
Check if padding is set
147 148 149 |
# File 'lib/strings/padder.rb', line 147 def empty? padding.empty? end |
#left ⇒ Integer
Left padding
127 128 129 |
# File 'lib/strings/padder.rb', line 127 def left @padding[3].to_i end |
#left=(value) ⇒ nil
Set left padding
138 139 140 |
# File 'lib/strings/padder.rb', line 138 def left=(value) @padding[3] = value end |
#right ⇒ Integer
Right padding
89 90 91 |
# File 'lib/strings/padder.rb', line 89 def right @padding[1].to_i end |
#right=(value) ⇒ Object
Set right padding
98 99 100 |
# File 'lib/strings/padder.rb', line 98 def right=(value) @padding[1] = value end |
#to_s ⇒ String
String represenation of this padder with padding values
156 157 158 |
# File 'lib/strings/padder.rb', line 156 def to_s inspect end |
#top ⇒ Integer
Top padding
69 70 71 |
# File 'lib/strings/padder.rb', line 69 def top @padding[0].to_i end |
#top=(value) ⇒ nil
Set top padding
80 81 82 |
# File 'lib/strings/padder.rb', line 80 def top=(value) @padding[0] = value end |