Class: RailsNewApp::MenuScreen
- Inherits:
-
Screen
- Object
- Screen
- RailsNewApp::MenuScreen
show all
- Defined in:
- lib/rails-new-app/screens/menu_screen.rb
Instance Attribute Summary
Attributes inherited from Screen
#config
Instance Method Summary
collapse
Methods inherited from Screen
#after_valid, #clean_input, clean_name, default, key, #process_user_input, #return_value, #validate_user_input
Constructor Details
#initialize(screens) ⇒ MenuScreen
Returns a new instance of MenuScreen.
3
4
5
6
|
# File 'lib/rails-new-app/screens/menu_screen.rb', line 3
def initialize(screens)
@screens = screens
@current_page = 1
end
|
Instance Method Details
#get_screen(option) ⇒ Object
8
9
10
|
# File 'lib/rails-new-app/screens/menu_screen.rb', line 8
def get_screen(option)
SCREENS.find { |x| x[:option] == option.to_s && x[:page] == @current_page }
end
|
#go_to_next_page ⇒ Object
40
41
42
|
# File 'lib/rails-new-app/screens/menu_screen.rb', line 40
def go_to_next_page
@current_page += 1
end
|
#go_to_previous_page ⇒ Object
44
45
46
|
# File 'lib/rails-new-app/screens/menu_screen.rb', line 44
def go_to_previous_page
@current_page -= 1
end
|
#next_step ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/rails-new-app/screens/menu_screen.rb', line 48
def next_step
case @input
when "0" then :review_and_confirm
when "n"
go_to_next_page
:rerender
when "p"
go_to_previous_page
:rerender
else get_screen(@input)[:class].key
end
end
|
#screen_text ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/rails-new-app/screens/menu_screen.rb', line 12
def screen_text
[].tap do |ls|
@screens.each do |s|
next if s[:option].nil?
next if s[:page] != @current_page
screen_name = s[:class].clean_name
ls << "#{s[:option]} : #{screen_name}"
end
ls << ""
ls << "n : Next menu" if @current_page == 1
ls << "p : Previous menu" if @current_page == 2
ls << "0 : Review and confirm"
ls << ""
ls << "Type the number of the menu and press enter:"
end.join("\n")
end
|
#valid?(input) ⇒ Boolean
30
31
32
33
34
35
36
37
38
|
# File 'lib/rails-new-app/screens/menu_screen.rb', line 30
def valid?(input)
case input
when "0" then true
when "n" then @current_page == 1
when "p" then @current_page == 2
when /\A\d\z/ then get_screen(input)
else false
end
end
|