Class: Vedeu::Cursors::Move Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

  • direction (Symbol)
  • offset (Fixnum)


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

#directionSymbol (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.

Returns:

  • (Symbol)

    The direction to move the cursor.



52
53
54
# File 'lib/vedeu/cursors/move.rb', line 52

def direction
  @direction
end

#nameNilClass|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.

Returns:

  • (NilClass|Symbol|String)

    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

#offsetSymbol (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.

Returns:

  • (Symbol)

    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.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

  • direction (Symbol)
  • offset (Fixnum)

Returns:



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

#cursorVedeu::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

#directionsHash<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.

Returns:

  • (Hash<Symbol => Proc>)


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

#moveNilClass|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.

Returns:



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.

Returns:



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.

Returns:



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.

Returns:



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.

Returns:



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.

Returns:



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.

Returns:



102
103
104
# File 'lib/vedeu/cursors/move.rb', line 102

def valid_up?
  (cursor.oy - offset) > 0
end