Class: Vedeu::Focus

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/support/focus.rb

Overview

Maintains which interface is current in focus.

Instance Method Summary collapse

Constructor Details

#initializeFocus



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

Parameters:

  • name (String)

Returns:

  • (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

Parameters:

  • name (String)

Returns:

  • (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

#currentString

Returns:

  • (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_itemString

Returns:

  • (String)


43
44
45
46
47
# File 'lib/vedeu/support/focus.rb', line 43

def next_item
  storage.rotate!

  current
end

#prev_itemString

Returns:

  • (String)


50
51
52
53
54
# File 'lib/vedeu/support/focus.rb', line 50

def prev_item
  storage.rotate!(-1)

  current
end

#register_eventsTrueClass

Returns:

  • (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.

Returns:

  • (TrueClass|FalseClass)


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

#storageArray (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:

  • (Array)


78
79
80
# File 'lib/vedeu/support/focus.rb', line 78

def storage
  @storage ||= []
end