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`.



64
65
66
# File 'lib/vedeu/borders/refresh.rb', line 64

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)


78
79
80
# File 'lib/vedeu/borders/refresh.rb', line 78

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:



53
54
55
56
57
# File 'lib/vedeu/borders/refresh.rb', line 53

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.



85
86
87
# File 'lib/vedeu/borders/refresh.rb', line 85

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)


177
178
179
180
181
# File 'lib/vedeu/borders/refresh.rb', line 177

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:



117
118
119
120
121
122
123
124
125
# File 'lib/vedeu/borders/refresh.rb', line 117

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:



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

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:



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

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:



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

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:



194
195
196
197
198
# File 'lib/vedeu/borders/refresh.rb', line 194

def build_horizontal(position, y_coordinate)
  Array.new(bordered_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:



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

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:



158
159
160
# File 'lib/vedeu/borders/refresh.rb', line 158

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:



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

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:



69
70
71
# File 'lib/vedeu/borders/refresh.rb', line 69

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:



249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/vedeu/borders/refresh.rb', line 249

def captionbar
  return build_bottom if render_caption.empty?

  caption_starts_at = (width - render_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    = render_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.



186
187
188
# File 'lib/vedeu/borders/refresh.rb', line 186

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.



206
207
208
# File 'lib/vedeu/borders/refresh.rb', line 206

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)


215
216
217
218
219
# File 'lib/vedeu/borders/refresh.rb', line 215

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:



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

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

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

#render_captionVedeu::Borders::Caption (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 An optional caption for when the bottom border is to be shown.

Returns:



102
103
104
# File 'lib/vedeu/borders/refresh.rb', line 102

def render_caption
  @_caption ||= Vedeu::Borders::Caption.coerce(caption, width)
end

#render_titleVedeu::Borders::Title (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 An optional title for when the top border is to be shown.

Returns:



108
109
110
# File 'lib/vedeu/borders/refresh.rb', line 108

def render_title
  @_title ||= Vedeu::Borders::Title.coerce(title, width)
end

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


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

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:



268
269
270
271
272
273
274
275
276
277
# File 'lib/vedeu/borders/refresh.rb', line 268

def titlebar
  return build_top if render_title.empty?

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

    char.border = nil
    char.value  = render_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)


239
240
241
242
243
# File 'lib/vedeu/borders/refresh.rb', line 239

def top
  return [] unless top?

  [build_top_left, titlebar, build_top_right].compact
end