Class: Vedeu::Borders::Title Private

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

Caption

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:



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

#horizontalArray<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.

Returns:



82
83
84
# File 'lib/vedeu/borders/title.rb', line 82

def horizontal
  @horizontal
end

#nameString|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.

Returns:

  • (String|Symbol)


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.

Parameters:

Returns:



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.

Parameters:

  • char (String)
  • x (Fixnum)

Returns:

  • (Hash<Symbol => void>)


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

#borderVedeu::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

#charactersArray<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.

Returns:

  • (Array<String>)


113
114
115
# File 'lib/vedeu/borders/title.rb', line 113

def characters
  pad.chars
end

#charsArray<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.

Returns:



120
121
122
# File 'lib/vedeu/borders/title.rb', line 120

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.

Parameters:

Returns:



42
43
44
# File 'lib/vedeu/borders/title.rb', line 42

def eql?(other)
  self.class == other.class && value == other.value
end

#geometryVedeu::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.



125
126
127
# File 'lib/vedeu/borders/title.rb', line 125

def geometry
  @_geometry ||= Vedeu.geometries.by_name(name)
end

#padString (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.

Examples:

value = 'Truncated!'
width = 20
# => ' Truncated! '

width = 10
# => ' Trunca '

Returns:

  • (String)

See Also:



141
142
143
# File 'lib/vedeu/borders/title.rb', line 141

def pad
  truncate.center(truncate.size + 2)
end

#renderArray<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..(start_index + (size - 1))] = chars

  horizontal
end

#sizeFixnum (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.

Returns:

  • (Fixnum)


148
149
150
# File 'lib/vedeu/borders/title.rb', line 148

def size
  pad.size
end

#start_indexFixnum (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.

Returns:

  • (Fixnum)


153
154
155
# File 'lib/vedeu/borders/title.rb', line 153

def start_index
  1
end

#to_sString 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.

Returns:

  • (String)


63
64
65
# File 'lib/vedeu/borders/title.rb', line 63

def to_s
  value.to_s
end

#truncateString (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.

Examples:

value = 'Truncated!'
width = 20
# => 'Truncated!'

width = 10
# => 'Trunca'

Returns:

  • (String)


171
172
173
# File 'lib/vedeu/borders/title.rb', line 171

def truncate
  value.chomp.slice(0...(width - 4))
end

#valueString 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.

Returns:

  • (String)


71
72
73
# File 'lib/vedeu/borders/title.rb', line 71

def value
  @value || ''
end

#widthFixnum (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.

Returns:

  • (Fixnum)


178
179
180
# File 'lib/vedeu/borders/title.rb', line 178

def width
  horizontal.size
end

#xFixnum (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.

Returns:

  • (Fixnum)


183
184
185
# File 'lib/vedeu/borders/title.rb', line 183

def x
  geometry.bx + start_index
end

#yFixnum (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.

Returns:

  • (Fixnum)


188
189
190
# File 'lib/vedeu/borders/title.rb', line 188

def y
  geometry.y
end