Class: Vedeu::Interface
- Inherits:
-
Object
- Object
- Vedeu::Interface
- Extended by:
- Forwardable
- Includes:
- Coercions, Presentation
- Defined in:
- lib/vedeu/models/interface.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ String
- #cursor ⇒ String
- #defaults ⇒ Hash private private
-
#define(&block) ⇒ Object
[].
- #geometry ⇒ Geometry
- #initialize(attributes = {}, &block) ⇒ Interface constructor
- #lines ⇒ Array
-
#method_missing(method, *args, &block) ⇒ Object
private
private
[].
- #out_of_bounds(name) ⇒ String private private
- #to_s ⇒ String
- #x_out_of_bounds?(value) ⇒ TrueClass|FalseClass private private
- #y_out_of_bounds?(value) ⇒ TrueClass|FalseClass private private
Methods included from Presentation
Methods included from Coercions
Constructor Details
#initialize(attributes = {}, &block) ⇒ Interface
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vedeu/models/interface.rb', line 33 def initialize(attributes = {}, &block) @attributes = defaults.merge!(attributes) @name = @attributes[:name] @group = @attributes[:group] @delay = @attributes[:delay] if block_given? @self_before_instance_eval = eval('self', block.binding) instance_eval(&block) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
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 [].
140 141 142 |
# File 'lib/vedeu/models/interface.rb', line 140 def method_missing(method, *args, &block) @self_before_instance_eval.send(method, *args, &block) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
13 14 15 |
# File 'lib/vedeu/models/interface.rb', line 13 def attributes @attributes end |
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
13 14 15 |
# File 'lib/vedeu/models/interface.rb', line 13 def delay @delay end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
13 14 15 |
# File 'lib/vedeu/models/interface.rb', line 13 def group @group end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/vedeu/models/interface.rb', line 13 def name @name end |
Class Method Details
.build(attributes = {}, &block) ⇒ Hash
18 19 20 |
# File 'lib/vedeu/models/interface.rb', line 18 def self.build(attributes = {}, &block) new(attributes, &block).attributes end |
.define(attributes = {}, &block) ⇒ Object
Returns [].
26 27 28 |
# File 'lib/vedeu/models/interface.rb', line 26 def self.define(attributes = {}, &block) new(attributes).define(&block) end |
Instance Method Details
#clear ⇒ String
98 99 100 |
# File 'lib/vedeu/models/interface.rb', line 98 def clear Clear.call(self) end |
#cursor ⇒ String
82 83 84 85 86 87 88 89 90 |
# File 'lib/vedeu/models/interface.rb', line 82 def cursor @cursor ||= if attributes[:cursor] == true Esc.string('show_cursor') else Esc.string('hide_cursor') end end |
#defaults ⇒ Hash (private)
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.
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/vedeu/models/interface.rb', line 106 def defaults { name: '', group: '', lines: [], colour: {}, style: '', geometry: {}, cursor: true, delay: 0.0 } end |
#define(&block) ⇒ Object
Returns [].
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vedeu/models/interface.rb', line 54 def define(&block) instance_eval(&block) if block_given? if attributes[:name].nil? || attributes[:name].empty? fail InvalidSyntax, 'Interfaces and views must have a `name`.' end Vedeu::Buffers.create(attributes) Vedeu.event("_refresh_#{attributes[:name]}_".to_sym, { delay: attributes[:delay] }) do Vedeu::Buffers.refresh(attributes[:name]) end self end |
#geometry ⇒ Geometry
77 78 79 |
# File 'lib/vedeu/models/interface.rb', line 77 def geometry @geometry ||= Geometry.new(attributes[:geometry]) end |
#lines ⇒ Array
72 73 74 |
# File 'lib/vedeu/models/interface.rb', line 72 def lines @lines ||= Line.coercer(attributes[:lines]) end |
#out_of_bounds(name) ⇒ String (private)
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.
121 122 123 124 |
# File 'lib/vedeu/models/interface.rb', line 121 def out_of_bounds(name) "Note: For this terminal, the value of '#{name}' may lead to content " \ "that is outside the viewable area." end |
#to_s ⇒ String
93 94 95 |
# File 'lib/vedeu/models/interface.rb', line 93 def to_s Render.call(self) end |
#x_out_of_bounds?(value) ⇒ TrueClass|FalseClass (private)
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.
134 135 136 |
# File 'lib/vedeu/models/interface.rb', line 134 def x_out_of_bounds?(value) value < 1 || value > Terminal.width end |
#y_out_of_bounds?(value) ⇒ TrueClass|FalseClass (private)
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.
128 129 130 |
# File 'lib/vedeu/models/interface.rb', line 128 def y_out_of_bounds?(value) value < 1 || value > Terminal.height end |