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.

Direct Known Subclasses

Caption

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:



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.

Parameters:

Returns:



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

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

Returns:

  • (Array<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.

Returns:

  • (Boolean)


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.

Parameters:

Returns:

  • (Boolean)


57
58
59
# File 'lib/vedeu/borders/title.rb', line 57

def eql?(other)
  self.class == other.class && value == other.value
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:



99
100
101
# File 'lib/vedeu/borders/title.rb', line 99

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

#sizeFixnum

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)


65
66
67
# File 'lib/vedeu/borders/title.rb', line 65

def size
  pad.size
end

#to_sString

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)


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

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)


117
118
119
# File 'lib/vedeu/borders/title.rb', line 117

def truncate
  title.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 or an empty string.

Returns:

  • (String)


79
80
81
# File 'lib/vedeu/borders/title.rb', line 79

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 given width or the width of the terminal.

Returns:

  • (Fixnum)


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

def width
  @width || Vedeu.width
end