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
-
#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_to_hash ⇒ Hash<Symbol => String> private
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#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_to_hash ⇒ Has<Symbol => Fixnum> private
-
#to_hash ⇒ Hash<Symbol => Hash, String>
Returns a Hash of all the values before coercion.
- #to_html(options = {}) ⇒ String
-
#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.
Methods included from Presentation
#render_colour, #render_position, #render_style, #to_s
Methods included from Presentation::Styles
Methods included from Presentation::Colour
#background, #background=, #colour, #colour=, #foreground, #foreground=
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Views::Char
Returns a new instance of Vedeu::Views::Char.
43 44 45 46 47 48 |
# File 'lib/vedeu/models/views/char.rb', line 43 def initialize(attributes = {}) @attributes = attributes @border = @attributes[:border] @parent = @attributes[:parent] @value = @attributes[:value] end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
18 19 20 |
# File 'lib/vedeu/models/views/char.rb', line 18 def attributes @attributes end |
#border ⇒ NilClass|Symbol
22 23 24 |
# File 'lib/vedeu/models/views/char.rb', line 22 def border @border end |
#parent ⇒ Vedeu::Views::Line
26 27 28 |
# File 'lib/vedeu/models/views/char.rb', line 26 def parent @parent end |
Instance Method Details
#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.
57 58 59 |
# File 'lib/vedeu/models/views/char.rb', line 57 def chars [] end |
#colour_to_hash ⇒ Hash<Symbol => String> (private)
139 140 141 142 143 144 |
# File 'lib/vedeu/models/views/char.rb', line 139 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.
65 66 67 68 |
# File 'lib/vedeu/models/views/char.rb', line 65 def eql?(other) self.class == other.class && value == other.value && position == other.position end |
#parent_to_hash ⇒ Hash<Symbol => String> (private)
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/vedeu/models/views/char.rb', line 147 def parent_to_hash if parent { background: parent.background.to_s, foreground: parent.foreground.to_s, style: parent.style.to_s, } else {} end end |
#position ⇒ Vedeu::Geometry::Position
72 73 74 |
# File 'lib/vedeu/models/views/char.rb', line 72 def position @position = Vedeu::Geometry::Position.coerce(@attributes[:position]) end |
#position=(value) ⇒ Vedeu::Geometry::Position
Sets the position of the Vedeu::Views::Char.
80 81 82 83 |
# File 'lib/vedeu/models/views/char.rb', line 80 def position=(value) @position = @attributes[:position] = Vedeu::Geometry::Position .coerce(value) end |
#position_to_hash ⇒ Has<Symbol => Fixnum> (private)
162 163 164 165 166 167 |
# File 'lib/vedeu/models/views/char.rb', line 162 def position_to_hash { y: y, x: x, } end |
#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.
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/vedeu/models/views/char.rb', line 118 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
132 133 134 |
# File 'lib/vedeu/models/views/char.rb', line 132 def to_html( = {}) @to_html ||= Vedeu::Views::HTMLChar.render(self, ) end |
#x ⇒ Fixnum|NilClass
Returns the x position for the Vedeu::Views::Char when set.
99 100 101 |
# File 'lib/vedeu/models/views/char.rb', line 99 def x position.x if position end |
#y ⇒ Fixnum|NilClass
Returns the y position for the Vedeu::Views::Char when set.
106 107 108 |
# File 'lib/vedeu/models/views/char.rb', line 106 def y position.y if position end |