Class: Vedeu::Views::Char
- Inherits:
-
Object
- Object
- Vedeu::Views::Char
- Includes:
- Comparable, Presentation
- Defined in:
- lib/vedeu/models/views/char.rb
Overview
A Char represents a single character of the terminal. It is a container for the a single character in a Stream.
Though a multi-character String can be passed as a value, only the first character is returned in the escape sequence.
Instance Attribute Summary collapse
- #attributes ⇒ Hash readonly
- #border ⇒ NilClass|Symbol
- #name ⇒ String|Symbol
- #parent ⇒ Vedeu::Views::Line
- #value ⇒ String
Instance Method Summary collapse
-
#background ⇒ Vedeu::Colours::Background
included
from Presentation::Colour
When the background colour for the model exists, return it, otherwise returns the parent background colour, or an empty Vedeu::Colours::Background.
-
#background=(value) ⇒ Vedeu::Colours::Background
included
from Presentation::Colour
Allows the setting of the background colour by coercing the given value into a Vedeu::Colours::Background colour.
- #cell? ⇒ Boolean
-
#chars ⇒ Array
When Output::Viewport#show has less lines that required to fill the visible area of the interface, it creates a line that contains a single Char containing a space (0x20); later, attempts to call ‘#chars` on an expected Line and fail; this method fixes that.
- #colour ⇒ Vedeu::Colours::Colour included from Presentation::Colour
-
#colour=(value) ⇒ Vedeu::Colours::Colour
included
from Presentation::Colour
Allows the setting of the model’s colour by coercing the given value into a Vedeu::Colours::Colour.
- #colour_to_hash ⇒ Hash<Symbol => String> private
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#foreground ⇒ Vedeu::Colours::Foreground
included
from Presentation::Colour
When the foreground colour for the model exists, return it, otherwise returns the parent foreground colour, or an empty Vedeu::Colours::Foreground.
-
#foreground=(value) ⇒ Vedeu::Colours::Foreground
included
from Presentation::Colour
Allows the setting of the foreground colour by coercing the given value into a Vedeu::Colours::Foreground colour.
-
#initialize(attributes = {}) ⇒ Vedeu::Views::Char
constructor
Returns a new instance of Vedeu::Views::Char.
- #interface ⇒ Vedeu::Interfaces::Interface
- #parent_to_hash ⇒ Hash<Symbol => String> private
- #position ⇒ Vedeu::Geometry::Position
-
#position=(value) ⇒ Vedeu::Geometry::Position
Sets the position of the Vedeu::Views::Char.
-
#position? ⇒ Boolean
included
from Presentation
private
Returns a boolean indicating the model has a position attribute.
- #position_to_hash ⇒ Hash<Symbol => Fixnum> private
-
#render_colour ⇒ String
included
from Presentation
private
Renders the colour attributes of the receiver and yields (to then render the styles).
- #render_position ⇒ String included from Presentation private
-
#render_style ⇒ String
included
from Presentation
private
Renders the style attributes of the receiver and yields (to then render the next model, or finally, the content).
-
#style ⇒ Vedeu::Presentation::Style
included
from Presentation::Styles
When the style for the model exists, return it, otherwise returns the parent style, or an empty Presentation::Style.
-
#style=(value) ⇒ Vedeu::Presentation::Style
included
from Presentation::Styles
Allows the setting of the style by coercing the given value into a Presentation::Style.
-
#to_hash ⇒ Hash<Symbol => Hash, String>
Returns a Hash of all the values before coercion.
- #to_html(options = {}) ⇒ String
-
#to_s ⇒ String
(also: #to_str)
included
from Presentation
Converts the colours and styles to escape sequences, and when the parent model has previously set the colour and style, reverts back to that for consistent formatting.
-
#x ⇒ Fixnum|NilClass
Returns the x position for the Vedeu::Views::Char when set.
-
#y ⇒ Fixnum|NilClass
Returns the y position for the Vedeu::Views::Char when set.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Views::Char
Returns a new instance of Vedeu::Views::Char.
58 59 60 61 62 63 64 |
# File 'lib/vedeu/models/views/char.rb', line 58 def initialize(attributes = {}) @attributes = attributes @border = @attributes[:border] @name = @attributes[:name] @parent = @attributes[:parent] @value = @attributes[:value] end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
27 28 29 |
# File 'lib/vedeu/models/views/char.rb', line 27 def attributes @attributes end |
#border ⇒ NilClass|Symbol
31 32 33 |
# File 'lib/vedeu/models/views/char.rb', line 31 def border @border end |
#name ⇒ String|Symbol
35 36 37 |
# File 'lib/vedeu/models/views/char.rb', line 35 def name @name end |
#parent ⇒ Vedeu::Views::Line
39 40 41 |
# File 'lib/vedeu/models/views/char.rb', line 39 def parent @parent end |
#value ⇒ String
112 113 114 115 116 |
# File 'lib/vedeu/models/views/char.rb', line 112 def value return @value unless border Vedeu::EscapeSequences::Esc.border { @value } end |
Instance Method Details
#background ⇒ Vedeu::Colours::Background Originally defined in module Presentation::Colour
When the background colour for the model exists, return it, otherwise returns the parent background colour, or an empty Vedeu::Colours::Background.
#background=(value) ⇒ Vedeu::Colours::Background Originally defined in module Presentation::Colour
Allows the setting of the background colour by coercing the given value into a Vedeu::Colours::Background colour.
#cell? ⇒ Boolean
67 68 69 |
# File 'lib/vedeu/models/views/char.rb', line 67 def cell? false end |
#chars ⇒ Array
When Output::Viewport#show has less lines that required to fill the visible area of the interface, it creates a line that contains a single Vedeu::Views::Char containing a space (0x20); later, attempts to call ‘#chars` on an expected Line and fail; this method fixes that.
78 79 80 |
# File 'lib/vedeu/models/views/char.rb', line 78 def chars [] end |
#colour ⇒ Vedeu::Colours::Colour Originally defined in module Presentation::Colour
#colour=(value) ⇒ Vedeu::Colours::Colour Originally defined in module Presentation::Colour
Allows the setting of the model’s colour by coercing the given value into a Vedeu::Colours::Colour.
#colour_to_hash ⇒ Hash<Symbol => String> (private)
162 163 164 165 166 167 |
# File 'lib/vedeu/models/views/char.rb', line 162 def colour_to_hash { background: background.to_s, foreground: foreground.to_s, } end |
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
86 87 88 89 |
# File 'lib/vedeu/models/views/char.rb', line 86 def eql?(other) self.class == other.class && value == other.value && position == other.position end |
#foreground ⇒ Vedeu::Colours::Foreground Originally defined in module Presentation::Colour
When the foreground colour for the model exists, return it, otherwise returns the parent foreground colour, or an empty Vedeu::Colours::Foreground.
#foreground=(value) ⇒ Vedeu::Colours::Foreground Originally defined in module Presentation::Colour
Allows the setting of the foreground colour by coercing the given value into a Vedeu::Colours::Foreground colour.
#interface ⇒ Vedeu::Interfaces::Interface
93 94 95 |
# File 'lib/vedeu/models/views/char.rb', line 93 def interface @interface ||= Vedeu.interfaces.by_name(name) end |
#parent_to_hash ⇒ Hash<Symbol => String> (private)
170 171 172 173 174 175 176 177 178 |
# File 'lib/vedeu/models/views/char.rb', line 170 def parent_to_hash return {} unless parent { background: parent.background.to_s, foreground: parent.foreground.to_s, style: parent.style.to_s, } end |
#position ⇒ Vedeu::Geometry::Position
98 99 100 |
# File 'lib/vedeu/models/views/char.rb', line 98 def position @position = Vedeu::Geometry::Position.coerce(@attributes[:position]) end |
#position=(value) ⇒ Vedeu::Geometry::Position
Sets the position of the Vedeu::Views::Char.
106 107 108 109 |
# File 'lib/vedeu/models/views/char.rb', line 106 def position=(value) @position = @attributes[:position] = Vedeu::Geometry::Position .coerce(value) end |
#position? ⇒ Boolean (private) Originally defined in module Presentation
Returns a boolean indicating the model has a position attribute.
#position_to_hash ⇒ Hash<Symbol => Fixnum> (private)
181 182 183 184 185 186 |
# File 'lib/vedeu/models/views/char.rb', line 181 def position_to_hash { y: y, x: x, } end |
#render_colour ⇒ String (private) Originally defined in module Presentation
Renders the colour attributes of the receiver and yields (to then render the styles).
#render_position ⇒ String (private) Originally defined in module Presentation
#render_style ⇒ String (private) Originally defined in module Presentation
Renders the style attributes of the receiver and yields (to then render the next model, or finally, the content).
#style ⇒ Vedeu::Presentation::Style Originally defined in module Presentation::Styles
When the style for the model exists, return it, otherwise returns the parent style, or an empty Vedeu::Presentation::Style.
#style=(value) ⇒ Vedeu::Presentation::Style Originally defined in module Presentation::Styles
Allows the setting of the style by coercing the given value into a Vedeu::Presentation::Style.
#to_hash ⇒ Hash<Symbol => Hash, String>
From this hash we should be able to construct a new instance of Vedeu::Views::Char, however, at the moment, ‘:parent` cannot be coerced.
Returns a Hash of all the values before coercion.
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/vedeu/models/views/char.rb', line 140 def to_hash { border: border.to_s, colour: colour_to_hash, name: name.to_s, parent: parent_to_hash, position: position_to_hash, style: style.to_s, value: value, } end |
#to_html(options = {}) ⇒ String
155 156 157 |
# File 'lib/vedeu/models/views/char.rb', line 155 def to_html( = {}) @to_html ||= Vedeu::Views::HTMLChar.render(self, ) end |
#to_s ⇒ String Also known as: to_str Originally defined in module Presentation
Converts the colours and styles to escape sequences, and when the parent model has previously set the colour and style, reverts back to that for consistent formatting.
#x ⇒ Fixnum|NilClass
Returns the x position for the Vedeu::Views::Char when set.
121 122 123 |
# File 'lib/vedeu/models/views/char.rb', line 121 def x position.x if position end |
#y ⇒ Fixnum|NilClass
Returns the y position for the Vedeu::Views::Char when set.
128 129 130 |
# File 'lib/vedeu/models/views/char.rb', line 128 def y position.y if position end |