Class: Vedeu::Border
- Inherits:
-
Object
- Object
- Vedeu::Border
- Includes:
- Model
- Defined in:
- lib/vedeu/output/border.rb
Overview
Refer to UTF-8 U+2500 to U+257F for border characters. More details can be found at: en.wikipedia.org/wiki/Box-drawing_character
Provides the mechanism to decorate an interface with a border on all edges, or specific edges. The characters which are used for the border parts (e.g. the corners, verticals and horizontals) can be customised as can the colours and styles.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#bottom_left ⇒ Object
Returns the value of attribute bottom_left.
-
#bottom_right ⇒ Object
Returns the value of attribute bottom_right.
- #colour ⇒ Vedeu::Colour
-
#enabled ⇒ Object
(also: #enabled?)
readonly
Returns the value of attribute enabled.
-
#horizontal ⇒ Object
Returns the value of attribute horizontal.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#show_bottom ⇒ Object
(also: #bottom?)
Returns the value of attribute show_bottom.
-
#show_left ⇒ Object
(also: #left?)
Returns the value of attribute show_left.
-
#show_right ⇒ Object
(also: #right?)
Returns the value of attribute show_right.
-
#show_top ⇒ Object
(also: #top?)
Returns the value of attribute show_top.
- #style ⇒ Vedeu::Style
-
#top_left ⇒ Object
Returns the value of attribute top_left.
-
#top_right ⇒ Object
Returns the value of attribute top_right.
-
#vertical ⇒ Object
Returns the value of attribute vertical.
Attributes included from Model
Instance Method Summary collapse
- #border(value, type = :border) ⇒ Vedeu::Char private
-
#bottom ⇒ String
Renders the bottom border for the interface.
-
#defaults ⇒ Hash
private
The default values for a new instance of this class.
-
#height ⇒ Fixnum
Returns the height of the interface determined by whether a top, bottom, both or neither borders are shown.
-
#initialize(attributes = {}) ⇒ Border
constructor
Returns a new instance of Border.
- #interface ⇒ Vedeu::Interface private
-
#left ⇒ String
Renders the left border for the interface.
-
#right ⇒ String
Renders the right border for the interface.
-
#to_s ⇒ Boolean
Returns a string representation of the border for the interface without content.
-
#top ⇒ String
Renders the top border for the interface.
-
#width ⇒ Fixnum
Returns the width of the interface determined by whether a left, right, both or neither borders are shown.
Methods included from Model
#demodulize, #deputy, #dsl_class, included, #store
Constructor Details
#initialize(attributes = {}) ⇒ Border
Returns a new instance of Border.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/vedeu/output/border.rb', line 64 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @enabled = @attributes[:enabled] @bottom_left = @attributes[:bottom_left] @bottom_right = @attributes[:bottom_right] @show_bottom = @attributes[:show_bottom] @show_left = @attributes[:show_left] @show_right = @attributes[:show_right] @show_top = @attributes[:show_top] @top_left = @attributes[:top_left] @top_right = @attributes[:top_right] @horizontal = @attributes[:horizontal] @vertical = @attributes[:vertical] @name = @attributes[:name] @colour = @attributes[:colour] @repository = Vedeu.borders @style = @attributes[:style] end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
17 18 19 |
# File 'lib/vedeu/output/border.rb', line 17 def attributes @attributes end |
#bottom_left ⇒ Object
Returns the value of attribute bottom_left.
17 18 19 |
# File 'lib/vedeu/output/border.rb', line 17 def bottom_left @bottom_left end |
#bottom_right ⇒ Object
Returns the value of attribute bottom_right.
17 18 19 |
# File 'lib/vedeu/output/border.rb', line 17 def bottom_right @bottom_right end |
#colour ⇒ Vedeu::Colour
122 123 124 |
# File 'lib/vedeu/output/border.rb', line 122 def colour @colour end |
#enabled ⇒ Object (readonly) Also known as: enabled?
Returns the value of attribute enabled.
29 30 31 |
# File 'lib/vedeu/output/border.rb', line 29 def enabled @enabled end |
#horizontal ⇒ Object
Returns the value of attribute horizontal.
17 18 19 |
# File 'lib/vedeu/output/border.rb', line 17 def horizontal @horizontal end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/vedeu/output/border.rb', line 29 def name @name end |
#show_bottom ⇒ Object Also known as: bottom?
Returns the value of attribute show_bottom.
17 18 19 |
# File 'lib/vedeu/output/border.rb', line 17 def show_bottom @show_bottom end |
#show_left ⇒ Object Also known as: left?
Returns the value of attribute show_left.
17 18 19 |
# File 'lib/vedeu/output/border.rb', line 17 def show_left @show_left end |
#show_right ⇒ Object Also known as: right?
Returns the value of attribute show_right.
17 18 19 |
# File 'lib/vedeu/output/border.rb', line 17 def show_right @show_right end |
#show_top ⇒ Object Also known as: top?
Returns the value of attribute show_top.
17 18 19 |
# File 'lib/vedeu/output/border.rb', line 17 def show_top @show_top end |
#style ⇒ Vedeu::Style
134 135 136 |
# File 'lib/vedeu/output/border.rb', line 134 def style @style end |
#top_left ⇒ Object
Returns the value of attribute top_left.
17 18 19 |
# File 'lib/vedeu/output/border.rb', line 17 def top_left @top_left end |
#top_right ⇒ Object
Returns the value of attribute top_right.
17 18 19 |
# File 'lib/vedeu/output/border.rb', line 17 def top_right @top_right end |
#vertical ⇒ Object
Returns the value of attribute vertical.
17 18 19 |
# File 'lib/vedeu/output/border.rb', line 17 def vertical @vertical end |
Instance Method Details
#border(value, type = :border) ⇒ Vedeu::Char (private)
210 211 212 213 214 215 216 217 |
# File 'lib/vedeu/output/border.rb', line 210 def border(value, type = :border) Vedeu::Char.new({ value: value, parent: interface, colour: colour, style: style, position: nil, border: type }) end |
#bottom ⇒ String
Renders the bottom border for the interface.
157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/vedeu/output/border.rb', line 157 def bottom return [] unless bottom? out = [] out << border(bottom_left, :bottom_left) if left? width.times do out << border(horizontal, :bottom_horizontal) end out << border(bottom_right, :bottom_right) if right? out.flatten end |
#defaults ⇒ Hash (private)
The default values for a new instance of this class.
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/vedeu/output/border.rb', line 227 def defaults { bottom_left: "\x6D", # └ bottom_right: "\x6A", # ┘ client: nil, colour: {}, enabled: false, horizontal: "\x71", # ─ name: '', show_bottom: true, show_left: true, show_right: true, show_top: true, style: [], top_left: "\x6C", # ┌ top_right: "\x6B", # ┐ vertical: "\x78", # │ } end |
#height ⇒ Fixnum
Returns the height of the interface determined by whether a top, bottom, both or neither borders are shown.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/vedeu/output/border.rb', line 106 def height return interface.height unless enabled? if top? && bottom? interface.height - 2 elsif top? || bottom? interface.height - 1 else interface.height end end |
#interface ⇒ Vedeu::Interface (private)
220 221 222 |
# File 'lib/vedeu/output/border.rb', line 220 def interface @interface ||= Vedeu.interfaces.find(name) end |
#left ⇒ String
Renders the left border for the interface.
174 175 176 177 178 |
# File 'lib/vedeu/output/border.rb', line 174 def left return [] unless left? border(vertical, :left_vertical) end |
#right ⇒ String
Renders the right border for the interface.
183 184 185 186 187 |
# File 'lib/vedeu/output/border.rb', line 183 def right return [] unless right? border(vertical, :right_vertical) end |
#to_s ⇒ Boolean
Returns a string representation of the border for the interface without content.
149 150 151 152 |
# File 'lib/vedeu/output/border.rb', line 149 def to_s render = Vedeu::Viewport.new(interface).render render.map { |line| line.flatten.join }.join("\n") end |
#top ⇒ String
Renders the top border for the interface.
192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/vedeu/output/border.rb', line 192 def top return [] unless top? out = [] out << border(top_left, :top_left) if left? width.times do out << border(horizontal, :top_horizontal) end out << border(top_right, :top_right) if right? out.flatten end |
#width ⇒ Fixnum
Returns the width of the interface determined by whether a left, right, both or neither borders are shown.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/vedeu/output/border.rb', line 87 def width return interface.width unless enabled? if left? && right? interface.width - 2 elsif left? || right? interface.width - 1 else interface.width end end |