Class: Vedeu::Cursor
- Inherits:
-
Object
- Object
- Vedeu::Cursor
- Extended by:
- Forwardable
- Includes:
- Model
- Defined in:
- lib/vedeu/cursor/cursor.rb
Overview
Each interface has its own Cursor which maintains the position and visibility of the cursor within that interface.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ox ⇒ Object
readonly
Returns the value of attribute ox.
-
#oy ⇒ Object
readonly
Returns the value of attribute oy.
-
#position ⇒ Object
readonly
private
Returns the value of attribute position.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Attributes included from Model
Instance Method Summary collapse
-
#defaults ⇒ Hash
private
The default values for a new instance of this class.
-
#initialize(attributes = {}) ⇒ Cursor
constructor
Returns a new instance of Cursor.
-
#sequence ⇒ String
private
Returns the escape sequence to position the cursor and set its visibility.
-
#to_s(&block) ⇒ String
Returns an escape sequence to position the cursor and set its visibility.
-
#visibility ⇒ String
private
Returns the escape sequence for setting the visibility of the cursor.
Methods included from Model
#demodulize, #deputy, #dsl_class, included, #store
Constructor Details
#initialize(attributes = {}) ⇒ Cursor
Returns a new instance of Cursor.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vedeu/cursor/cursor.rb', line 35 def initialize(attributes = {}) # Hack because Repository#by_name creates Cursor objects with just a # name. if attributes.is_a?(String) attributes = { name: attributes } end @attributes = defaults.merge!(attributes) @name = @attributes.fetch(:name) @ox = @attributes.fetch(:ox) @oy = @attributes.fetch(:oy) @repository = @attributes.fetch(:repository) @state = Vedeu::Visible.coerce(@attributes.fetch(:state)) @x = @attributes.fetch(:x) @y = @attributes.fetch(:y) @position = Vedeu::Position.new(@y, @x) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
19 20 21 |
# File 'lib/vedeu/cursor/cursor.rb', line 19 def attributes @attributes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/vedeu/cursor/cursor.rb', line 19 def name @name end |
#ox ⇒ Object (readonly)
Returns the value of attribute ox.
19 20 21 |
# File 'lib/vedeu/cursor/cursor.rb', line 19 def ox @ox end |
#oy ⇒ Object (readonly)
Returns the value of attribute oy.
19 20 21 |
# File 'lib/vedeu/cursor/cursor.rb', line 19 def oy @oy end |
#position ⇒ Object (readonly, private)
Returns the value of attribute position.
73 74 75 |
# File 'lib/vedeu/cursor/cursor.rb', line 73 def position @position end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
19 20 21 |
# File 'lib/vedeu/cursor/cursor.rb', line 19 def state @state end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
19 20 21 |
# File 'lib/vedeu/cursor/cursor.rb', line 19 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
19 20 21 |
# File 'lib/vedeu/cursor/cursor.rb', line 19 def y @y end |
Instance Method Details
#defaults ⇒ Hash (private)
The default values for a new instance of this class.
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/vedeu/cursor/cursor.rb', line 78 def defaults { name: '', ox: 0, oy: 0, repository: Vedeu.cursors, state: false, x: 1, y: 1, } end |
#sequence ⇒ String (private)
Returns the escape sequence to position the cursor and set its visibility.
93 94 95 |
# File 'lib/vedeu/cursor/cursor.rb', line 93 def sequence [ position, visibility ].join end |
#to_s(&block) ⇒ String
Returns an escape sequence to position the cursor and set its visibility. When passed a block, will position the cursor, yield and return the original position.
61 62 63 64 65 66 67 68 69 |
# File 'lib/vedeu/cursor/cursor.rb', line 61 def to_s(&block) if block_given? [ sequence, yield, sequence ].join else sequence end end |
#visibility ⇒ String (private)
Returns the escape sequence for setting the visibility of the cursor.
100 101 102 |
# File 'lib/vedeu/cursor/cursor.rb', line 100 def visibility state.cursor end |