Class: Vedeu::Borders::Render
- Inherits:
-
Object
- Object
- Vedeu::Borders::Render
- Extended by:
- Forwardable
- Includes:
- Common
- Defined in:
- lib/vedeu/borders/render.rb
Overview
Renders the provided border.
Instance Attribute Summary collapse
- #border ⇒ Vedeu::Borders::Border readonly protected
Class Method Summary collapse
Instance Method Summary collapse
-
#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.
-
#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.
- #geometry ⇒ Vedeu::Geometry::Geometry private
-
#initialize(border) ⇒ Vedeu::Borders::Render
constructor
Returns a new instance of Vedeu::Borders::Render.
-
#interface ⇒ Vedeu::Models::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.
- #render ⇒ Array<Array<Vedeu::Views::Char>>
-
#right(iy = 0) ⇒ String
private
Renders the right border for the interface.
-
#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.
Methods included from Common
#demodulize, #present?, #snake_case
Constructor Details
#initialize(border) ⇒ Vedeu::Borders::Render
Returns a new instance of Vedeu::Borders::Render.
52 53 54 |
# File 'lib/vedeu/borders/render.rb', line 52 def initialize(border) @border = border end |
Instance Attribute Details
#border ⇒ Vedeu::Borders::Border (readonly, protected)
73 74 75 |
# File 'lib/vedeu/borders/render.rb', line 73 def border @border end |
Class Method Details
.with(border) ⇒ Array<Array<Vedeu::Views::Char>>
44 45 46 |
# File 'lib/vedeu/borders/render.rb', line 44 def self.with(border) new(border).render end |
Instance Method Details
#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.
141 142 143 144 145 |
# File 'lib/vedeu/borders/render.rb', line 141 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)
82 83 84 85 86 87 88 89 |
# File 'lib/vedeu/borders/render.rb', line 82 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.
115 116 117 |
# File 'lib/vedeu/borders/render.rb', line 115 def build_bottom build_horizontal(:bottom_horizontal, yn) end |
#build_bottom_left ⇒ Vedeu::Views::Char (private)
Creates the bottom left border character.
94 95 96 |
# File 'lib/vedeu/borders/render.rb', line 94 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.
101 102 103 |
# File 'lib/vedeu/borders/render.rb', line 101 def build_bottom_right build(bottom_right, :bottom_right, yn, xn) if right? end |
#build_horizontal(position, y_coordinate) ⇒ Array<Vedeu::Views::Char> (private)
156 157 158 159 160 |
# File 'lib/vedeu/borders/render.rb', line 156 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.
108 109 110 |
# File 'lib/vedeu/borders/render.rb', line 108 def build_top build_horizontal(:bottom_horizontal, y) end |
#build_top_left ⇒ Vedeu::Views::Char (private)
Creates the top left border character.
122 123 124 |
# File 'lib/vedeu/borders/render.rb', line 122 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.
129 130 131 |
# File 'lib/vedeu/borders/render.rb', line 129 def build_top_right build(top_right, :top_right, y, xn) if right? end |
#caption? ⇒ Boolean (private)
Return boolean indicating whether this border has a non-empty caption.
250 251 252 |
# File 'lib/vedeu/borders/render.rb', line 250 def caption? present?(caption) end |
#caption_characters ⇒ Array<String> (private)
276 277 278 |
# File 'lib/vedeu/borders/render.rb', line 276 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.
266 267 268 |
# File 'lib/vedeu/borders/render.rb', line 266 def caption_fits? width > caption_characters.size end |
#caption_padded ⇒ String (private)
Pads the caption with a single whitespace either side.
308 309 310 |
# File 'lib/vedeu/borders/render.rb', line 308 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.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/vedeu/borders/render.rb', line 208 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 |
#geometry ⇒ Vedeu::Geometry::Geometry (private)
148 149 150 |
# File 'lib/vedeu/borders/render.rb', line 148 def geometry Vedeu.geometries.by_name(name) end |
#interface ⇒ Vedeu::Models::Interface (private) Also known as: parent
The parent of a border is always an interface.
165 166 167 |
# File 'lib/vedeu/borders/render.rb', line 165 def interface @interface ||= Vedeu.interfaces.by_name(name) end |
#left(iy = 0) ⇒ String (private)
Renders the left border for the interface.
174 175 176 177 178 |
# File 'lib/vedeu/borders/render.rb', line 174 def left(iy = 0) return [] unless left? build(vertical, :left_vertical, (by + iy), x) end |
#render ⇒ Array<Array<Vedeu::Views::Char>>
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/vedeu/borders/render.rb', line 57 def render return [] unless enabled? Vedeu.timer("Bordering: '#{name}'") do out = [top, bottom] height.times { |y| out << [left(y), right(y)] } out.flatten end end |
#right(iy = 0) ⇒ String (private)
Renders the right border for the interface.
184 185 186 187 188 |
# File 'lib/vedeu/borders/render.rb', line 184 def right(iy = 0) return [] unless right? build(vertical, :right_vertical, (by + iy), xn) end |
#title? ⇒ Boolean (private)
Return boolean indicating whether this border has a non-empty title.
242 243 244 |
# File 'lib/vedeu/borders/render.rb', line 242 def title? present?(title) end |
#title_characters ⇒ Array<String> (private)
271 272 273 |
# File 'lib/vedeu/borders/render.rb', line 271 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.
258 259 260 |
# File 'lib/vedeu/borders/render.rb', line 258 def title_fits? width > title_characters.size end |
#title_padded ⇒ String (private)
Pads the title with a single whitespace either side.
292 293 294 |
# File 'lib/vedeu/borders/render.rb', line 292 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.
227 228 229 230 231 232 233 234 235 236 |
# File 'lib/vedeu/borders/render.rb', line 227 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.
198 199 200 201 202 |
# File 'lib/vedeu/borders/render.rb', line 198 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.
344 345 346 |
# File 'lib/vedeu/borders/render.rb', line 344 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.
326 327 328 |
# File 'lib/vedeu/borders/render.rb', line 326 def truncated_title title.chomp.slice(0..(width - 5)) end |