class RailsNewApp::MenuScreen

Public Class Methods

new(screens) click to toggle source
# File lib/rails-new-app/screens/menu_screen.rb, line 3
def initialize(screens)
  @screens = screens
  @current_page = 1
end

Public Instance Methods

get_screen(option) click to toggle source
# 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() click to toggle source
# File lib/rails-new-app/screens/menu_screen.rb, line 40
def go_to_next_page
  @current_page += 1
end
go_to_previous_page() click to toggle source
# File lib/rails-new-app/screens/menu_screen.rb, line 44
def go_to_previous_page
  @current_page -= 1
end
next_step() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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