Class: Vedeu::Focus
- Inherits:
-
Object
- Object
- Vedeu::Focus
- Defined in:
- lib/vedeu/support/focus.rb
Overview
Maintains which interface is current in focus.
Instance Method Summary collapse
- #add(name) ⇒ Array
- #by_name(name) ⇒ String
- #current ⇒ String
- #initialize ⇒ Focus constructor
- #next_item ⇒ String
- #prev_item ⇒ String
- #register_events ⇒ TrueClass
- #registered?(name) ⇒ TrueClass|FalseClass private private
- #storage ⇒ Array private private
Constructor Details
#initialize ⇒ Focus
7 8 9 10 11 |
# File 'lib/vedeu/support/focus.rb', line 7 def initialize register_events self end |
Instance Method Details
#add(name) ⇒ Array
15 16 17 18 19 20 21 22 23 |
# File 'lib/vedeu/support/focus.rb', line 15 def add(name) if registered?(name) storage else storage << name end end |
#by_name(name) ⇒ String
27 28 29 30 31 32 33 |
# File 'lib/vedeu/support/focus.rb', line 27 def by_name(name) fail InterfaceNotFound unless storage.include?(name) storage.rotate!(storage.index(name)) current end |
#current ⇒ String
36 37 38 39 40 |
# File 'lib/vedeu/support/focus.rb', line 36 def current fail NoInterfacesDefined if storage.empty? storage.first end |
#next_item ⇒ String
43 44 45 46 47 |
# File 'lib/vedeu/support/focus.rb', line 43 def next_item storage.rotate! current end |
#prev_item ⇒ String
50 51 52 53 54 |
# File 'lib/vedeu/support/focus.rb', line 50 def prev_item storage.rotate!(-1) current end |
#register_events ⇒ TrueClass
57 58 59 60 61 62 63 64 |
# File 'lib/vedeu/support/focus.rb', line 57 def register_events Vedeu.event(:_focus_next_) { next_item } Vedeu.event(:_focus_prev_) { prev_item } Vedeu.event(:_focus_by_name_) { |name| by_name(name) } Vedeu.event(:_focussed_) { current } true end |
#registered?(name) ⇒ 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.
70 71 72 73 74 |
# File 'lib/vedeu/support/focus.rb', line 70 def registered?(name) return false if storage.empty? storage.include?(name) end |
#storage ⇒ Array (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.
78 79 80 |
# File 'lib/vedeu/support/focus.rb', line 78 def storage @storage ||= [] end |