Class: ScreenManager
- Inherits:
-
Object
- Object
- ScreenManager
- Defined in:
- lib/delve/screen_manager.rb
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize ⇒ ScreenManager
constructor
A new instance of ScreenManager.
- #pop_screen ⇒ Object
- #push_screen(screen) ⇒ Object
- #render(display) ⇒ Object
- #update(input) ⇒ Object
Constructor Details
#initialize ⇒ ScreenManager
Returns a new instance of ScreenManager.
2 3 4 |
# File 'lib/delve/screen_manager.rb', line 2 def initialize @screen_stack = Array.new end |
Instance Method Details
#empty? ⇒ Boolean
6 7 8 |
# File 'lib/delve/screen_manager.rb', line 6 def empty? @screen_stack.empty? end |
#pop_screen ⇒ Object
14 15 16 |
# File 'lib/delve/screen_manager.rb', line 14 def pop_screen @screen_stack.pop end |
#push_screen(screen) ⇒ Object
10 11 12 |
# File 'lib/delve/screen_manager.rb', line 10 def push_screen(screen) @screen_stack.push screen end |
#render(display) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/delve/screen_manager.rb', line 24 def render(display) raise 'Cannot render when no screens are present' if empty? raise 'Cannot render when display is nil' unless display bottom = @screen_stack.length - 1 screens = @screen_stack.length - 1 (0..screens).reverse_each do |i| if !@screen_stack[i].partial? break end bottom = i-1 end (bottom..screens).each do |i| @screen_stack[i].render display end end |
#update(input) ⇒ Object
18 19 20 21 22 |
# File 'lib/delve/screen_manager.rb', line 18 def update(input) raise 'Cannot handle key when no screens are present' if empty? raise 'Cannot handle key when input is nil' unless input @screen_stack.last.update input end |