Class: Vedeu::Borders::Refresh
- Inherits:
-
Object
- Object
- Vedeu::Borders::Refresh
- Extended by:
- Forwardable
- Includes:
- Common
- Defined in:
- lib/vedeu/borders/refresh.rb
Overview
Renders and refreshes the named border.
Instance Attribute Summary collapse
- #name ⇒ String|Symbol readonly protected
Class Method Summary collapse
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable is nil or empty.
- #border ⇒ Vedeu::Borders::Border private
-
#bottom ⇒ String
private
Renders the bottom border for the interface.
- #build(value, type = :border, iy = 0, ix = 0) ⇒ Vedeu::Views::Char private
-
#build_bottom ⇒ Array<Vedeu::Views::Char>
private
Creates a bottom border character.
-
#build_bottom_left ⇒ Vedeu::Views::Char
private
Creates the bottom left border character.
-
#build_bottom_right ⇒ Vedeu::Views::Char
private
Creates the bottom right border character.
- #build_horizontal(position, y_coordinate) ⇒ Array<Vedeu::Views::Char> private
-
#build_top ⇒ Array<Vedeu::Views::Char>
private
Creates a top border character.
-
#build_top_left ⇒ Vedeu::Views::Char
private
Creates the top left border character.
-
#build_top_right ⇒ Vedeu::Views::Char
private
Creates the top right border character.
- #by_name ⇒ Array<Array<Vedeu::Views::Char>> (also: #render)
-
#caption? ⇒ Boolean
private
Return boolean indicating whether this border has a non-empty caption.
- #caption_characters ⇒ Array<String> private
-
#caption_fits? ⇒ Boolean
private
Return boolean indicating whether the caption fits within the width of the bottom border.
-
#caption_padded ⇒ String
private
Pads the caption with a single whitespace either side.
-
#captionbar ⇒ Array<Vedeu::Views::Char>
private
Overwrite the border from #build_horizontal on the bottom border to include the caption if given.
-
#demodulize(klass) ⇒ String
included
from Common
Removes the module part from the expression in the string.
- #geometry ⇒ Vedeu::Geometry::Geometry private
-
#initialize(name = Vedeu.focus) ⇒ Vedeu::Borders::Refresh
constructor
Returns a new instance of Vedeu::Borders::Refresh.
-
#interface ⇒ Vedeu::Interfaces::Interface
(also: #parent)
private
The parent of a border is always an interface.
-
#left(iy = 0) ⇒ String
private
Renders the left border for the interface.
- #output ⇒ Array<Array<Vedeu::Views::Char>> private
-
#present?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable has a useful value.
-
#right(iy = 0) ⇒ String
private
Renders the right border for the interface.
-
#snake_case(name) ⇒ String
included
from Common
Converts a class name to a lowercase snake case string.
-
#title? ⇒ Boolean
private
Return boolean indicating whether this border has a non-empty title.
- #title_characters ⇒ Array<String> private
-
#title_fits? ⇒ Boolean
private
Return boolean indicating whether the title fits within the width of the top border.
-
#title_padded ⇒ String
private
Pads the title with a single whitespace either side.
-
#titlebar ⇒ Array<Vedeu::Views::Char>
private
Overwrite the border from #build_horizontal on the top border to include the title if given.
-
#top ⇒ String
private
Renders the top border for the interface.
-
#truncated_caption ⇒ String
private
Truncates the caption 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 caption.
-
#truncated_title ⇒ String
private
Truncates the title 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 title.
Constructor Details
#initialize(name = Vedeu.focus) ⇒ Vedeu::Borders::Refresh
Returns a new instance of Vedeu::Borders::Refresh.
60 61 62 |
# File 'lib/vedeu/borders/refresh.rb', line 60 def initialize(name = Vedeu.focus) @name = present?(name) ? name : Vedeu.focus end |
Instance Attribute Details
#name ⇒ String|Symbol (readonly, protected)
74 75 76 |
# File 'lib/vedeu/borders/refresh.rb', line 74 def name @name end |
Class Method Details
.by_name(name = Vedeu.focus) ⇒ Array<Array<Vedeu::Views::Char>>
49 50 51 52 53 |
# File 'lib/vedeu/borders/refresh.rb', line 49 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
Returns a boolean indicating whether a variable is nil or empty.
#border ⇒ Vedeu::Borders::Border (private)
79 80 81 |
# File 'lib/vedeu/borders/refresh.rb', line 79 def border @border ||= Vedeu.borders.by_name(name) end |
#bottom ⇒ String (private)
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.
158 159 160 161 162 |
# File 'lib/vedeu/borders/refresh.rb', line 158 def bottom return [] unless bottom? [build_bottom_left, , build_bottom_right].compact end |
#build(value, type = :border, iy = 0, ix = 0) ⇒ Vedeu::Views::Char (private)
99 100 101 102 103 104 105 106 |
# File 'lib/vedeu/borders/refresh.rb', line 99 def build(value, type = :border, iy = 0, ix = 0) Vedeu::Views::Char.new(value: value, parent: interface, colour: colour, style: style, position: [iy, ix], border: type) end |
#build_bottom ⇒ Array<Vedeu::Views::Char> (private)
Creates a bottom border character.
132 133 134 |
# File 'lib/vedeu/borders/refresh.rb', line 132 def build_bottom build_horizontal(:bottom_horizontal, yn) end |
#build_bottom_left ⇒ Vedeu::Views::Char (private)
Creates the bottom left border character.
111 112 113 |
# File 'lib/vedeu/borders/refresh.rb', line 111 def build_bottom_left build(bottom_left, :bottom_left, yn, x) if left? end |
#build_bottom_right ⇒ Vedeu::Views::Char (private)
Creates the bottom right border character.
118 119 120 |
# File 'lib/vedeu/borders/refresh.rb', line 118 def build_bottom_right build(bottom_right, :bottom_right, yn, xn) if right? end |
#build_horizontal(position, y_coordinate) ⇒ Array<Vedeu::Views::Char> (private)
173 174 175 176 177 |
# File 'lib/vedeu/borders/refresh.rb', line 173 def build_horizontal(position, y_coordinate) Array.new(width) do |ix| build(horizontal, position, y_coordinate, (bx + ix)) end end |
#build_top ⇒ Array<Vedeu::Views::Char> (private)
Creates a top border character.
125 126 127 |
# File 'lib/vedeu/borders/refresh.rb', line 125 def build_top build_horizontal(:bottom_horizontal, y) end |
#build_top_left ⇒ Vedeu::Views::Char (private)
Creates the top left border character.
139 140 141 |
# File 'lib/vedeu/borders/refresh.rb', line 139 def build_top_left build(top_left, :top_left, y, x) if left? end |
#build_top_right ⇒ Vedeu::Views::Char (private)
Creates the top right border character.
146 147 148 |
# File 'lib/vedeu/borders/refresh.rb', line 146 def build_top_right build(top_right, :top_right, y, xn) if right? end |
#by_name ⇒ Array<Array<Vedeu::Views::Char>> Also known as: render
65 66 67 |
# File 'lib/vedeu/borders/refresh.rb', line 65 def by_name Vedeu.render_output(output) if enabled? && visible? end |
#caption? ⇒ Boolean (private)
Return boolean indicating whether this border has a non-empty caption.
267 268 269 |
# File 'lib/vedeu/borders/refresh.rb', line 267 def caption? present?(caption) end |
#caption_characters ⇒ Array<String> (private)
293 294 295 |
# File 'lib/vedeu/borders/refresh.rb', line 293 def caption_characters @caption_characters ||= caption_padded.chars end |
#caption_fits? ⇒ Boolean (private)
Return boolean indicating whether the caption fits within the width of the bottom border.
283 284 285 |
# File 'lib/vedeu/borders/refresh.rb', line 283 def caption_fits? width > caption_characters.size end |
#caption_padded ⇒ String (private)
Pads the caption with a single whitespace either side.
325 326 327 |
# File 'lib/vedeu/borders/refresh.rb', line 325 def caption_padded truncated_caption.center(truncated_caption.size + 2) end |
#captionbar ⇒ Array<Vedeu::Views::Char> (private)
Overwrite the border from #build_horizontal on the bottom border to include the caption if given.
225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/vedeu/borders/refresh.rb', line 225 def return build_bottom unless caption? && caption_fits? caption_starts_at = (width - caption_characters.size) - 2 caption_char = 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_char] caption_char += 1 end end |
#demodulize(klass) ⇒ String Originally defined in module Common
Removes the module part from the expression in the string.
#geometry ⇒ Vedeu::Geometry::Geometry (private)
165 166 167 |
# File 'lib/vedeu/borders/refresh.rb', line 165 def geometry Vedeu.geometries.by_name(name) end |
#interface ⇒ Vedeu::Interfaces::Interface (private) Also known as: parent
The parent of a border is always an interface.
182 183 184 |
# File 'lib/vedeu/borders/refresh.rb', line 182 def interface @interface ||= Vedeu.interfaces.by_name(name) end |
#left(iy = 0) ⇒ String (private)
Renders the left border for the interface.
191 192 193 194 195 |
# File 'lib/vedeu/borders/refresh.rb', line 191 def left(iy = 0) return [] unless left? build(vertical, :left_vertical, (by + iy), x) end |
#output ⇒ Array<Array<Vedeu::Views::Char>> (private)
84 85 86 87 88 89 90 91 92 |
# File 'lib/vedeu/borders/refresh.rb', line 84 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
Returns a boolean indicating whether a variable has a useful value.
#right(iy = 0) ⇒ String (private)
Renders the right border for the interface.
201 202 203 204 205 |
# File 'lib/vedeu/borders/refresh.rb', line 201 def right(iy = 0) return [] unless right? build(vertical, :right_vertical, (by + iy), xn) end |
#snake_case(name) ⇒ String Originally defined in module Common
Converts a class name to a lowercase snake case string.
#title? ⇒ Boolean (private)
Return boolean indicating whether this border has a non-empty title.
259 260 261 |
# File 'lib/vedeu/borders/refresh.rb', line 259 def title? present?(title) end |
#title_characters ⇒ Array<String> (private)
288 289 290 |
# File 'lib/vedeu/borders/refresh.rb', line 288 def title_characters @title_characters ||= title_padded.chars end |
#title_fits? ⇒ Boolean (private)
Return boolean indicating whether the title fits within the width of the top border.
275 276 277 |
# File 'lib/vedeu/borders/refresh.rb', line 275 def title_fits? width > title_characters.size end |
#title_padded ⇒ String (private)
Pads the title with a single whitespace either side.
309 310 311 |
# File 'lib/vedeu/borders/refresh.rb', line 309 def title_padded truncated_title.center(truncated_title.size + 2) end |
#titlebar ⇒ Array<Vedeu::Views::Char> (private)
Overwrite the border from #build_horizontal on the top border to include the title if given.
244 245 246 247 248 249 250 251 252 253 |
# File 'lib/vedeu/borders/refresh.rb', line 244 def return build_top unless title? && title_fits? build_top.each_with_index do |char, index| next if index == 0 || index > title_characters.size char.border = nil char.value = title_characters[(index - 1)] end end |
#top ⇒ String (private)
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.
215 216 217 218 219 |
# File 'lib/vedeu/borders/refresh.rb', line 215 def top return [] unless top? [build_top_left, , build_top_right].compact end |
#truncated_caption ⇒ String (private)
Truncates the caption 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 caption.
361 362 363 |
# File 'lib/vedeu/borders/refresh.rb', line 361 def truncated_caption caption.chomp.slice(0..(width - 5)) end |
#truncated_title ⇒ String (private)
Truncates the title 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 title.
343 344 345 |
# File 'lib/vedeu/borders/refresh.rb', line 343 def truncated_title title.chomp.slice(0..(width - 5)) end |