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.
The title is displayed within the top border of the interface/ view.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#horizontal ⇒ Array<Vedeu::Cells::Horizontal>
readonly
protected
private
An array of border characters.
- #name ⇒ String|Symbol readonly protected private
Class Method Summary collapse
- .render(name, value = '', horizontal = []) ⇒ Array<Vedeu::Cells::Horizontal|Vedeu::Cells::Char> private
Instance Method Summary collapse
- #attributes(char, x) ⇒ Hash<Symbol => void> private private
- #border ⇒ Vedeu::Borders::Border private private
-
#characters ⇒ Array<String>
private
private
Return the padded, truncated value as an Array of String.
- #chars ⇒ Array<Vedeu::Cells::Horizontal|Vedeu::Cells::Char> private private
-
#empty? ⇒ Boolean
private
private
Return boolean indicating whether the value is empty.
- #end_index ⇒ Fixnum private private
-
#eql?(other) ⇒ Boolean
(also: #==)
private
An object is equal when its values are the same.
- #geometry ⇒ Vedeu::Geometries::Geometry private private
-
#initialize(name, value = '', horizontal = []) ⇒ 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.
-
#render ⇒ Array<Vedeu::Cells::Horizontal|Vedeu::Cells::Char>
private
Overwrite the border from Border#build_horizontal on the top border to include the title if given.
-
#size ⇒ Fixnum
private
private
Return the size of the padded, truncated value.
- #start_index ⇒ Fixnum private private
-
#to_s ⇒ String
(also: #to_str)
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 (a title or a caption) or an empty string.
-
#width ⇒ Fixnum
private
private
Return the size of the horizontal border given.
- #x ⇒ Fixnum private private
- #y ⇒ Fixnum private private
Constructor Details
#initialize(name, value = '', horizontal = []) ⇒ 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.
32 33 34 35 36 |
# File 'lib/vedeu/borders/title.rb', line 32 def initialize(name, value = '', horizontal = []) @name = name @value = value @horizontal = horizontal end |
Instance Attribute Details
#horizontal ⇒ Array<Vedeu::Cells::Horizontal> (readonly, protected)
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 An array of border characters.
82 83 84 |
# File 'lib/vedeu/borders/title.rb', line 82 def horizontal @horizontal end |
#name ⇒ String|Symbol (readonly, protected)
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/vedeu/borders/title.rb', line 86 def name @name end |
Class Method Details
.render(name, value = '', horizontal = []) ⇒ Array<Vedeu::Cells::Horizontal|Vedeu::Cells::Char>
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.
20 21 22 |
# File 'lib/vedeu/borders/title.rb', line 20 def self.render(name, value = '', horizontal = []) new(name, value, horizontal).render end |
Instance Method Details
#attributes(char, x) ⇒ Hash<Symbol => void> (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.
93 94 95 96 |
# File 'lib/vedeu/borders/title.rb', line 93 def attributes(char, x) border.attributes.merge(position: Vedeu::Geometries::Position.new(y, x), value: char) end |
#border ⇒ Vedeu::Borders::Border (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.
99 100 101 |
# File 'lib/vedeu/borders/title.rb', line 99 def border @_border ||= Vedeu.borders.by_name(name) end |
#characters ⇒ Array<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.
Return the padded, truncated value as an Array of String.
113 114 115 |
# File 'lib/vedeu/borders/title.rb', line 113 def characters pad.chars end |
#chars ⇒ Array<Vedeu::Cells::Horizontal|Vedeu::Cells::Char> (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.
104 105 106 107 108 |
# File 'lib/vedeu/borders/title.rb', line 104 def chars characters.each_with_index.map do |char, index| Vedeu::Cells::Char.new(attributes(char, x + index)) end end |
#empty? ⇒ Boolean (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 boolean indicating whether the value is empty.
120 121 122 |
# File 'lib/vedeu/borders/title.rb', line 120 def empty? value.empty? end |
#end_index ⇒ 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.
125 126 127 |
# File 'lib/vedeu/borders/title.rb', line 125 def end_index start_index + (size - 1) 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.
42 43 44 |
# File 'lib/vedeu/borders/title.rb', line 42 def eql?(other) self.class.equal?(other.class) && value == other.value end |
#geometry ⇒ Vedeu::Geometries::Geometry (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.
130 131 132 |
# File 'lib/vedeu/borders/title.rb', line 130 def geometry @_geometry ||= Vedeu.geometries.by_name(name) 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.
146 147 148 |
# File 'lib/vedeu/borders/title.rb', line 146 def pad truncate.center(truncate.size + 2) end |
#render ⇒ Array<Vedeu::Cells::Horizontal|Vedeu::Cells::Char>
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.
Overwrite the border from Border#build_horizontal on the top border to include the title if given.
52 53 54 55 56 57 58 |
# File 'lib/vedeu/borders/title.rb', line 52 def render return horizontal if empty? horizontal[start_index..end_index] = chars horizontal end |
#size ⇒ 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 size of the padded, truncated value.
153 154 155 |
# File 'lib/vedeu/borders/title.rb', line 153 def size pad.size end |
#start_index ⇒ 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.
158 159 160 |
# File 'lib/vedeu/borders/title.rb', line 158 def start_index 1 end |
#to_s ⇒ String Also known as: to_str
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.
63 64 65 |
# File 'lib/vedeu/borders/title.rb', line 63 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.
176 177 178 |
# File 'lib/vedeu/borders/title.rb', line 176 def truncate value.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 (a title or a caption) or an empty string.
71 72 73 |
# File 'lib/vedeu/borders/title.rb', line 71 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 size of the horizontal border given.
183 184 185 |
# File 'lib/vedeu/borders/title.rb', line 183 def width horizontal.size end |
#x ⇒ 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.
188 189 190 |
# File 'lib/vedeu/borders/title.rb', line 188 def x geometry.bx + start_index end |
#y ⇒ 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.
193 194 195 |
# File 'lib/vedeu/borders/title.rb', line 193 def y geometry.y end |