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
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.
- #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.
52 53 54 55 56 57 |
# File 'lib/vedeu/models/views/char.rb', line 52 def initialize(attributes = {}) @attributes = attributes @border = @attributes[:border] @parent = @attributes[:parent] @value = @attributes[:value] end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
26 27 28 |
# File 'lib/vedeu/models/views/char.rb', line 26 def attributes @attributes end |
#border ⇒ NilClass|Symbol
30 31 32 |
# File 'lib/vedeu/models/views/char.rb', line 30 def border @border end |
#parent ⇒ Vedeu::Views::Line
34 35 36 |
# File 'lib/vedeu/models/views/char.rb', line 34 def parent @parent end |
#value ⇒ String
100 101 102 103 104 |
# File 'lib/vedeu/models/views/char.rb', line 100 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
60 61 62 |
# File 'lib/vedeu/models/views/char.rb', line 60 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.
71 72 73 |
# File 'lib/vedeu/models/views/char.rb', line 71 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)
149 150 151 152 153 154 |
# File 'lib/vedeu/models/views/char.rb', line 149 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.
79 80 81 82 |
# File 'lib/vedeu/models/views/char.rb', line 79 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.
#parent_to_hash ⇒ Hash<Symbol => String> (private)
157 158 159 160 161 162 163 164 165 |
# File 'lib/vedeu/models/views/char.rb', line 157 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
86 87 88 |
# File 'lib/vedeu/models/views/char.rb', line 86 def position @position = Vedeu::Geometry::Position.coerce(@attributes[:position]) end |
#position=(value) ⇒ Vedeu::Geometry::Position
Sets the position of the Vedeu::Views::Char.
94 95 96 97 |
# File 'lib/vedeu/models/views/char.rb', line 94 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)
168 169 170 171 172 173 |
# File 'lib/vedeu/models/views/char.rb', line 168 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.
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/vedeu/models/views/char.rb', line 128 def to_hash { border: border.to_s, colour: colour_to_hash, parent: parent_to_hash, position: position_to_hash, style: style.to_s, value: value, } end |
#to_html(options = {}) ⇒ String
142 143 144 |
# File 'lib/vedeu/models/views/char.rb', line 142 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.
109 110 111 |
# File 'lib/vedeu/models/views/char.rb', line 109 def x position.x if position end |
#y ⇒ Fixnum|NilClass
Returns the y position for the Vedeu::Views::Char when set.
116 117 118 |
# File 'lib/vedeu/models/views/char.rb', line 116 def y position.y if position end |