Class: Vedeu::Borders::Title Private
- Inherits:
-
Object
- Object
- Vedeu::Borders::Title
- Defined in:
- lib/vedeu/borders/title.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.
When a Border has a title, truncate it if the title is longer than the interface is wide, and pad with a space either side.
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#characters ⇒ Array<String>
private
Return the padded, truncated value as an Array of String.
-
#empty? ⇒ Boolean
private
Return boolean indicating whether the value is empty.
-
#eql?(other) ⇒ Boolean
(also: #==)
private
An object is equal when its values are the same.
-
#initialize(value = '', width = Vedeu.width) ⇒ Vedeu::Borders::Title|Vedeu::Borders::Caption
constructor
private
Returns a new instance of Vedeu::Borders::Title or Vedeu::Borders::Caption.
-
#pad ⇒ String
private
private
Pads the value with a single whitespace either side.
-
#size ⇒ Fixnum
private
Return the size of the padded, truncated value.
-
#to_s ⇒ String
private
Convert the value to a string.
-
#truncate ⇒ String
private
private
Truncates the value to the width of the interface, minus characters needed to ensure there is at least a single character of horizontal border and a whitespace on either side of the value.
-
#value ⇒ String
(also: #title, #caption)
private
Return the value or an empty string.
-
#width ⇒ Fixnum
private
private
Return the given width or the width of the terminal.
Constructor Details
#initialize(value = '', width = Vedeu.width) ⇒ Vedeu::Borders::Title|Vedeu::Borders::Caption
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.
Returns a new instance of Vedeu::Borders::Title or Vedeu::Borders::Caption.
34 35 36 37 |
# File 'lib/vedeu/borders/title.rb', line 34 def initialize(value = '', width = Vedeu.width) @value = value @width = width end |
Class Method Details
.coerce(value = '', width = Vedeu.width) ⇒ Vedeu::Borders::Title|Vedeu::Borders::Caption
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.
17 18 19 20 21 22 23 24 25 |
# File 'lib/vedeu/borders/title.rb', line 17 def self.coerce(value = '', width = Vedeu.width) if value.is_a?(self) value else new(value, width) end end |
Instance Method Details
#characters ⇒ Array<String>
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.
Return the padded, truncated value as an Array of String.
42 43 44 |
# File 'lib/vedeu/borders/title.rb', line 42 def characters pad.chars end |
#empty? ⇒ Boolean
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.
Return boolean indicating whether the value is empty.
49 50 51 |
# File 'lib/vedeu/borders/title.rb', line 49 def empty? value.empty? end |
#eql?(other) ⇒ Boolean Also known as: ==
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.
An object is equal when its values are the same.
57 58 59 |
# File 'lib/vedeu/borders/title.rb', line 57 def eql?(other) self.class == other.class && value == other.value end |
#pad ⇒ String (private)
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.
Pads the value with a single whitespace either side.
99 100 101 |
# File 'lib/vedeu/borders/title.rb', line 99 def pad truncate.center(truncate.size + 2) end |
#size ⇒ Fixnum
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.
Return the size of the padded, truncated value.
65 66 67 |
# File 'lib/vedeu/borders/title.rb', line 65 def size pad.size end |
#to_s ⇒ String
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 the value to a string.
72 73 74 |
# File 'lib/vedeu/borders/title.rb', line 72 def to_s value.to_s end |
#truncate ⇒ String (private)
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.
Truncates the value to the width of the interface, minus characters needed to ensure there is at least a single character of horizontal border and a whitespace on either side of the value.
117 118 119 |
# File 'lib/vedeu/borders/title.rb', line 117 def truncate title.chomp.slice(0...(width - 4)) end |
#value ⇒ String Also known as: title, caption
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.
Return the value or an empty string.
79 80 81 |
# File 'lib/vedeu/borders/title.rb', line 79 def value @value || '' end |
#width ⇒ Fixnum (private)
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.
Return the given width or the width of the terminal.
124 125 126 |
# File 'lib/vedeu/borders/title.rb', line 124 def width @width || Vedeu.width end |