Class: Vedeu::Cursors::Move Private
- Inherits:
-
Object
- Object
- Vedeu::Cursors::Move
- Extended by:
- Forwardable
- Defined in:
- lib/vedeu/cursors/move.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Provides the mechanism to move a named cursor in a given direction.
Instance Attribute Summary collapse
-
#direction ⇒ Symbol
readonly
protected
private
The direction to move the cursor.
-
#name ⇒ NilClass|Symbol|String
readonly
protected
private
The name of the model, the target model or the name of the associated model.
-
#offset ⇒ Symbol
readonly
protected
private
The number of characters to move the cursor in the given direction.
Class Method Summary collapse
Instance Method Summary collapse
-
#cursor ⇒ Vedeu::Cursors::Cursor
private
private
Returns the named cursor from the cursors repository.
- #directions ⇒ Hash<Symbol => Proc> private private
- #initialize(name, direction, offset) ⇒ Vedeu::Cursors::Move constructor private
- #move ⇒ NilClass|Vedeu::Cursors::Cursor private
- #valid? ⇒ Boolean private private
- #valid_direction? ⇒ Boolean private private
- #valid_down? ⇒ Boolean private private
- #valid_left? ⇒ Boolean private private
- #valid_right? ⇒ Boolean private private
- #valid_up? ⇒ Boolean private private
Constructor Details
#initialize(name, direction, offset) ⇒ Vedeu::Cursors::Move
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.
29 30 31 32 33 |
# File 'lib/vedeu/cursors/move.rb', line 29 def initialize(name, direction, offset) @name = name @direction = direction @offset = offset || 1 end |
Instance Attribute Details
#direction ⇒ Symbol (readonly, protected)
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 The direction to move the cursor.
52 53 54 |
# File 'lib/vedeu/cursors/move.rb', line 52 def direction @direction end |
#name ⇒ NilClass|Symbol|String (readonly, protected)
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 The name of the model, the target model or the name of the associated model.
48 49 50 |
# File 'lib/vedeu/cursors/move.rb', line 48 def name @name end |
#offset ⇒ Symbol (readonly, protected)
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 The number of characters to move the cursor in the given direction.
57 58 59 |
# File 'lib/vedeu/cursors/move.rb', line 57 def offset @offset end |
Class Method Details
.move(name, direction, offset) ⇒ NilClass|Vedeu::Cursors::Cursor
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.
21 22 23 |
# File 'lib/vedeu/cursors/move.rb', line 21 def self.move(name, direction, offset) new(name, direction, offset).move end |
Instance Method Details
#cursor ⇒ Vedeu::Cursors::Cursor (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 the named cursor from the cursors repository.
62 63 64 |
# File 'lib/vedeu/cursors/move.rb', line 62 def cursor @_cursor ||= Vedeu.cursors.by_name(name) end |
#directions ⇒ Hash<Symbol => Proc> (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.
67 68 69 70 71 72 73 74 |
# File 'lib/vedeu/cursors/move.rb', line 67 def directions { move_down: proc { valid_down? }, move_left: proc { valid_left? }, move_right: proc { valid_right? }, move_up: proc { valid_up? }, } end |
#move ⇒ NilClass|Vedeu::Cursors::Cursor
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.
36 37 38 39 40 41 42 |
# File 'lib/vedeu/cursors/move.rb', line 36 def move if visible? && valid? cursor.public_send(direction, offset) cursor.store { Vedeu.trigger(:_refresh_cursor_, name) } cursor end end |
#valid? ⇒ Boolean (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.
77 78 79 |
# File 'lib/vedeu/cursors/move.rb', line 77 def valid? valid_direction? && directions.fetch(direction).call end |
#valid_direction? ⇒ Boolean (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.
82 83 84 |
# File 'lib/vedeu/cursors/move.rb', line 82 def valid_direction? directions.keys.include?(direction) end |
#valid_down? ⇒ Boolean (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.
87 88 89 |
# File 'lib/vedeu/cursors/move.rb', line 87 def valid_down? true end |
#valid_left? ⇒ Boolean (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.
92 93 94 |
# File 'lib/vedeu/cursors/move.rb', line 92 def valid_left? (cursor.ox - offset) > 0 end |
#valid_right? ⇒ Boolean (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.
97 98 99 |
# File 'lib/vedeu/cursors/move.rb', line 97 def valid_right? true end |
#valid_up? ⇒ Boolean (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.
102 103 104 |
# File 'lib/vedeu/cursors/move.rb', line 102 def valid_up? (cursor.oy - offset) > 0 end |