Class: Vedeu::Geometries::Geometry
- Inherits:
-
Object
- Object
- Vedeu::Geometries::Geometry
- Extended by:
- Forwardable
- Includes:
- Repositories::Model
- Defined in:
- lib/vedeu/geometries/geometry.rb
Overview
Consider storing the Terminal size at the time of first
creation, this allows us to return the interface to its original dimensions if the terminal resizes back to normal size.
Calculates and provides interface geometry determined by both the client’s requirements and the terminal’s current viewing area.
Instance Attribute Summary collapse
- #client ⇒ Object
- #height ⇒ Fixnum writeonly
- #horizontal_alignment ⇒ Symbol
- #maximised ⇒ Boolean (also: #maximised?)
- #name ⇒ String|Symbol
- #repository ⇒ Vedeu::Repositories::Repository included from Repositories::Model
- #vertical_alignment ⇒ Symbol
- #width ⇒ Fixnum writeonly
- #x ⇒ Fixnum writeonly
- #xn ⇒ Fixnum writeonly
- #y ⇒ Fixnum writeonly
- #yn ⇒ Fixnum writeonly
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
- #area ⇒ Vedeu::Geometries::Area private
- #area_attributes ⇒ Hash<Symbol => Boolean|Fixnum> private
-
#attributes ⇒ Hash<Symbol => Boolean|Fixnum|String|Symbol| Vedeu::Geometries::Repository]
Hash<Symbol => Boolean|Fixnum|String|Symbol| Vedeu::Geometries::Repository].
-
#become(klass, attributes) ⇒ Class
included
from Common
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
#defaults ⇒ Hash<Symbol => Boolean|Fixnum|NilClass|String|Symbol| Vedeu::Geometries::Repository]
private
Returns the default options/attributes for this class.
-
#deputy(client = nil) ⇒ Vedeu::Geometries::DSL
Returns a DSL instance responsible for defining the DSL methods of this model.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#escape?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
#falsy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
#hash?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
#initialize(attributes = {}) ⇒ Vedeu::Geometries::Geometry
constructor
Returns a new instance of Vedeu::Geometries::Geometry.
-
#line_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
#maximise ⇒ Vedeu::Geometries::Geometry|NilClass
Will maximise the named interface geometry.
-
#numeric?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#snake_case(klass) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#store(&block) ⇒ void
included
from Repositories::Model
The model instance stored in the repository.
-
#stream_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#truthy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
#unmaximise ⇒ Vedeu::Geometries::Geometry|NilClass
Will unmaximise the named interface geometry.
-
#view_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::View.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Geometries::Geometry
Returns a new instance of Vedeu::Geometries::Geometry.
103 104 105 106 107 |
# File 'lib/vedeu/geometries/geometry.rb', line 103 def initialize(attributes = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#client ⇒ Object
85 86 87 |
# File 'lib/vedeu/geometries/geometry.rb', line 85 def client @client end |
#height=(value) ⇒ Fixnum (writeonly)
56 57 58 |
# File 'lib/vedeu/geometries/geometry.rb', line 56 def height=(value) @height = value end |
#horizontal_alignment ⇒ Symbol
44 45 46 |
# File 'lib/vedeu/geometries/geometry.rb', line 44 def horizontal_alignment @horizontal_alignment end |
#maximised ⇒ Boolean Also known as: maximised?
60 61 62 |
# File 'lib/vedeu/geometries/geometry.rb', line 60 def maximised @maximised end |
#name ⇒ String|Symbol
52 53 54 |
# File 'lib/vedeu/geometries/geometry.rb', line 52 def name @name end |
#repository ⇒ Vedeu::Repositories::Repository Originally defined in module Repositories::Model
#vertical_alignment ⇒ Symbol
48 49 50 |
# File 'lib/vedeu/geometries/geometry.rb', line 48 def vertical_alignment @vertical_alignment end |
#width=(value) ⇒ Fixnum (writeonly)
65 66 67 |
# File 'lib/vedeu/geometries/geometry.rb', line 65 def width=(value) @width = value end |
#x=(value) ⇒ Fixnum (writeonly)
69 70 71 |
# File 'lib/vedeu/geometries/geometry.rb', line 69 def x=(value) @x = value end |
#xn=(value) ⇒ Fixnum (writeonly)
73 74 75 |
# File 'lib/vedeu/geometries/geometry.rb', line 73 def xn=(value) @xn = value end |
#y=(value) ⇒ Fixnum (writeonly)
77 78 79 |
# File 'lib/vedeu/geometries/geometry.rb', line 77 def y=(value) @y = value end |
#yn=(value) ⇒ Fixnum (writeonly)
81 82 83 |
# File 'lib/vedeu/geometries/geometry.rb', line 81 def yn=(value) @yn = value end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable is nil or empty.
#area ⇒ Vedeu::Geometries::Area (private)
Investigate the differences between memoizing this and not memoizing. Memoizing saves ~80ms on running test suite and considerably impacts app responsiveness, however changes to the geometry (such as movement or maximising) are not reflected. (GL: 2016-01-11)
199 200 201 |
# File 'lib/vedeu/geometries/geometry.rb', line 199 def area Vedeu::Geometries::Area.from_attributes(area_attributes) end |
#area_attributes ⇒ Hash<Symbol => Boolean|Fixnum> (private)
204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/vedeu/geometries/geometry.rb', line 204 def area_attributes { horizontal_alignment: horizontal_alignment, maximised: maximised, name: name, vertical_alignment: vertical_alignment, x: @x.is_a?(Proc) ? @x.call : @x, xn: @xn.is_a?(Proc) ? @xn.call : @xn, width: @width.is_a?(Proc) ? @width.call : @width, y: @y.is_a?(Proc) ? @y.call : @y, yn: @yn.is_a?(Proc) ? @yn.call : @yn, height: @height.is_a?(Proc) ? @height.call : @height, } end |
#attributes ⇒ Hash<Symbol => Boolean|Fixnum|String|Symbol| Vedeu::Geometries::Repository]
Returns Hash<Symbol => Boolean|Fixnum|String|Symbol| Vedeu::Geometries::Repository].
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/vedeu/geometries/geometry.rb', line 111 def attributes { client: client, height: height, horizontal_alignment: horizontal_alignment, maximised: maximised, name: name, repository: repository, vertical_alignment: vertical_alignment, width: width, x: x, xn: xn, y: y, yn: yn, } end |
#become(klass, attributes) ⇒ Class Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts one class into another.
#boolean(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the value was a boolean.
#boolean?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Boolean.
#defaults ⇒ Hash<Symbol => Boolean|Fixnum|NilClass|String|Symbol| Vedeu::Geometries::Repository] (private)
Returns the default options/attributes for this class.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/vedeu/geometries/geometry.rb', line 223 def defaults { client: nil, height: nil, horizontal_alignment: :none, maximised: false, name: nil, repository: Vedeu.geometries, vertical_alignment: :none, width: nil, x: nil, xn: nil, y: nil, yn: nil, } end |
#deputy(client = nil) ⇒ Vedeu::Geometries::DSL
Returns a DSL instance responsible for defining the DSL methods of this model.
137 138 139 |
# File 'lib/vedeu/geometries/geometry.rb', line 137 def deputy(client = nil) Vedeu::Geometries::DSL.new(self, client) end |
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
145 146 147 |
# File 'lib/vedeu/geometries/geometry.rb', line 145 def eql?(other) self.class == other.class && name == other.name end |
#escape?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
#falsy?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value should be considered false.
#hash?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Hash.
#line_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::Line.
#maximise ⇒ Vedeu::Geometries::Geometry|NilClass
Will maximise the named interface geometry. This means it will occupy all of the available space on the terminal window.
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/vedeu/geometries/geometry.rb', line 157 def maximise return self if maximised? @maximised = true store do Vedeu.trigger(:_clear_) Vedeu.trigger(:_refresh_view_, name) end end |
#numeric?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Fixnum.
#present?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable has a useful value.
#snake_case(klass) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a class name to a lowercase snake case string.
#store(&block) ⇒ void Originally defined in module Repositories::Model
Perhaps some validation could be added here?
If a block is given, store the model, return the model after yielding.
This method returns an undefined value.
Returns The model instance stored in the repository.
#stream_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::Stream.
#string?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Fixnum.
#truthy?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value should be considered true.
#unmaximise ⇒ Vedeu::Geometries::Geometry|NilClass
Will unmaximise the named interface geometry. Previously, when a geometry was maximised, then triggering the unmaximise event will return it to its usual defined size (terminal size permitting: when the terminal has been resized, then the new geometry size should adapt).
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/vedeu/geometries/geometry.rb', line 178 def unmaximise return self unless maximised? @maximised = false store do Vedeu.trigger(:_clear_) Vedeu.trigger(:_refresh_) Vedeu.trigger(:_refresh_view_, name) end end |
#view_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::View.