Class: Vedeu::Borders::Refresh Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Common
Defined in:
lib/vedeu/borders/refresh.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.

Renders and refreshes the named border.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = Vedeu.focus) ⇒ Vedeu::Borders::Refresh

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::Refresh.

Parameters:

  • name (String|Symbol) (defaults to: Vedeu.focus)

    The name of the interface/view border to be refreshed. Defaults to ‘Vedeu.focus`.



62
63
64
# File 'lib/vedeu/borders/refresh.rb', line 62

def initialize(name = Vedeu.focus)
  @name = present?(name) ? name : Vedeu.focus
end

Instance Attribute Details

#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)


76
77
78
# File 'lib/vedeu/borders/refresh.rb', line 76

def name
  @name
end

Class Method Details

.by_name(name = Vedeu.focus) ⇒ Array<Array<Vedeu::Views::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.

Examples:

Vedeu.trigger(:_refresh_border_, name)

Parameters:

  • name (String|Symbol) (defaults to: Vedeu.focus)

    The name of the interface/view border to be refreshed. Defaults to ‘Vedeu.focus`.

Returns:



51
52
53
54
55
# File 'lib/vedeu/borders/refresh.rb', line 51

def self.by_name(name = Vedeu.focus)
  name || Vedeu.focus

  new(name).by_name
end

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

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 boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#borderObject (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 the border for the interface.



83
84
85
# File 'lib/vedeu/borders/refresh.rb', line 83

def border
  @border ||= Vedeu.borders.by_name(name)
end

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

Note:

If a caption has been specified, then the bottom border will include this caption unless the size of the interface is smaller than the padded caption length.

Renders the bottom border for the interface.

Returns:

  • (String)


163
164
165
166
167
# File 'lib/vedeu/borders/refresh.rb', line 163

def bottom
  return [] unless bottom?

  [build_bottom_left, captionbar, build_bottom_right].compact
end

#build(value, type = :border, iy = 0, ix = 0) ⇒ Vedeu::Views::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.

Parameters:

  • value (String)
  • type (Symbol|NilClass) (defaults to: :border)
  • iy (Fixnum) (defaults to: 0)
  • ix (Fixnum) (defaults to: 0)

Returns:



103
104
105
106
107
108
109
110
111
# File 'lib/vedeu/borders/refresh.rb', line 103

def build(value, type = :border, iy = 0, ix = 0)
  Vedeu::Views::Char.new(value:    value,
                         parent:   interface,
                         colour:   colour,
                         name:     name,
                         style:    style,
                         position: [iy, ix],
                         border:   type)
end

#build_bottomArray<Vedeu::Views::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.

Creates a bottom border character.

Returns:



137
138
139
# File 'lib/vedeu/borders/refresh.rb', line 137

def build_bottom
  build_horizontal(:bottom_horizontal, yn)
end

#build_bottom_leftVedeu::Views::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.

Creates the bottom left border character.

Returns:



116
117
118
# File 'lib/vedeu/borders/refresh.rb', line 116

def build_bottom_left
  build(bottom_left, :bottom_left, yn, x) if left?
end

#build_bottom_rightVedeu::Views::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.

Creates the bottom right border character.

Returns:



123
124
125
# File 'lib/vedeu/borders/refresh.rb', line 123

def build_bottom_right
  build(bottom_right, :bottom_right, yn, xn) if right?
end

#build_horizontal(position, y_coordinate) ⇒ Array<Vedeu::Views::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.

Parameters:

  • position (Symbol)

    Either :top_horizontal, or :bottom_horizontal.

  • y_coordinate (Fixnum)

    The value of either y or yn.

Returns:



180
181
182
183
184
# File 'lib/vedeu/borders/refresh.rb', line 180

def build_horizontal(position, y_coordinate)
  Array.new(width) do |ix|
    build(horizontal, position, y_coordinate, (bx + ix))
  end
end

#build_topArray<Vedeu::Views::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.

Creates a top border character.

Returns:



130
131
132
# File 'lib/vedeu/borders/refresh.rb', line 130

def build_top
  build_horizontal(:bottom_horizontal, y)
end

#build_top_leftVedeu::Views::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.

Creates the top left border character.

Returns:



144
145
146
# File 'lib/vedeu/borders/refresh.rb', line 144

def build_top_left
  build(top_left, :top_left, y, x) if left?
end

#build_top_rightVedeu::Views::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.

Creates the top right border character.

Returns:



151
152
153
# File 'lib/vedeu/borders/refresh.rb', line 151

def build_top_right
  build(top_right, :top_right, y, xn) if right?
end

#by_nameArray<Array<Vedeu::Views::Char>> Also known as: render

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:



67
68
69
# File 'lib/vedeu/borders/refresh.rb', line 67

def by_name
  Vedeu.render_output(output) if enabled? && visible?
end

#captionbarArray<Vedeu::Views::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.

Overwrite the border from #build_horizontal on the bottom border to include the caption if given.

Returns:



235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/vedeu/borders/refresh.rb', line 235

def captionbar
  return build_bottom if caption.empty?

  caption_starts_at = (width - caption.size) - 2

  caption_index = 0
  build_bottom.each_with_index do |char, index|
    next if index <= caption_starts_at || index > (width - 2)

    char.border   = nil
    char.value    = caption.characters[caption_index]
    caption_index += 1
  end
end

#demodulize(klass) ⇒ String Originally defined in module Common

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.

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#geometryObject (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 the geometry for the interface.



172
173
174
# File 'lib/vedeu/borders/refresh.rb', line 172

def geometry
  Vedeu.geometries.by_name(name)
end

#interfaceObject (private) Also known as: parent

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.

Note:

The parent of a border is always an interface.

Returns the interface by name.



192
193
194
# File 'lib/vedeu/borders/refresh.rb', line 192

def interface
  @interface ||= Vedeu.interfaces.by_name(name)
end

#left(iy = 0) ⇒ 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.

Renders the left border for the interface.

Parameters:

  • iy (Fixnum) (defaults to: 0)

Returns:

  • (String)


201
202
203
204
205
# File 'lib/vedeu/borders/refresh.rb', line 201

def left(iy = 0)
  return [] unless left?

  build(vertical, :left_vertical, (by + iy), x)
end

#outputArray<Array<Vedeu::Views::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.

Returns:



88
89
90
91
92
93
94
95
96
# File 'lib/vedeu/borders/refresh.rb', line 88

def output
  Vedeu.timer("Drawing border: '#{name}'".freeze) do
    out = [top, bottom]

    height.times { |y| out << [left(y), right(y)] }

    out.flatten
  end
end

#present?(variable) ⇒ Boolean Originally defined in module Common

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 boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#right(iy = 0) ⇒ 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.

Renders the right border for the interface.

Parameters:

  • iy (Fixnum) (defaults to: 0)

Returns:

  • (String)


211
212
213
214
215
# File 'lib/vedeu/borders/refresh.rb', line 211

def right(iy = 0)
  return [] unless right?

  build(vertical, :right_vertical, (by + iy), xn)
end

#snake_case(name) ⇒ String Originally defined in module Common

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.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)

#titlebarArray<Vedeu::Views::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.

Overwrite the border from #build_horizontal on the top border to include the title if given.

Returns:



254
255
256
257
258
259
260
261
262
263
# File 'lib/vedeu/borders/refresh.rb', line 254

def titlebar
  return build_top if title.empty?

  build_top.each_with_index do |char, index|
    next if index == 0 || index > title.size

    char.border = nil
    char.value  = title.characters[index - 1]
  end
end

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

Note:

If a title has been specified, then the top border will include this title unless the size of the interface is smaller than the padded title length.

Renders the top border for the interface.

Returns:

  • (String)


225
226
227
228
229
# File 'lib/vedeu/borders/refresh.rb', line 225

def top
  return [] unless top?

  [build_top_left, titlebar, build_top_right].compact
end