class Marvel101::CLI

Constants

LINE_LEN
SOURCE
STARTING_PAGES

Public Instance Methods

call() click to toggle source
# File lib/marvel_101/cli.rb, line 15
def call
  puts "\nWelcome to Marvel 101!"
  main_menu
end
display_main() click to toggle source
# File lib/marvel_101/cli.rb, line 54
def display_main
  puts "\n" + "-" * LINE_LEN
  puts "Here are your primary options:"
  STARTING_PAGES.each.with_index(1) {|page, idx| puts "#{idx}. #{page[0]}!"}
  puts "-" * LINE_LEN
  puts "You can also enter (E)xit to... exit"
  puts "Select a number from the options above and we'll get started!"
end
display_topic(topic) click to toggle source
# File lib/marvel_101/cli.rb, line 63
def display_topic(topic)
  break_len = (LINE_LEN - topic.name.size) / 2.0
  puts "\n" + "-" * break_len.floor + "#{topic.name}" + "-" * break_len.ceil
  topic.display
  puts "-" * LINE_LEN
  options_message(topic)
end
error(topic) click to toggle source
# File lib/marvel_101/cli.rb, line 87
def error(topic)
  puts "\nSorry, that wasn't a valid option. Let's try again."
  topic == "main" ? main_menu : topic_menu(topic)
end
exit_message() click to toggle source
# File lib/marvel_101/cli.rb, line 76
def exit_message
  puts "\nOh ok, well have a super day!"
end
main_menu() click to toggle source
options_message(topic) click to toggle source
# File lib/marvel_101/cli.rb, line 80
def options_message(topic)
  puts "Enter an option number for more info!" if topic.takes_input?
  puts "You can enter (M)ain to go back to the main menu or (E)xit to... exit"
  puts "Type (L)ist to return to #{topic.list.name} menu" if !topic.list?
  puts "Type (T)eam to return to #{topic.team.name} menu" if topic.has_team?
end
topic_menu(topic) click to toggle source
# File lib/marvel_101/cli.rb, line 35
def topic_menu(topic)
  topic.get_info unless topic.scraped
  display_topic(topic)
  print ">> "
  input = gets.chomp.downcase

  case input
  when "101","wiki" then open_link("url_#{input}".to_sym, topic)
  when "source" then open_link(:url, topic)
  when "e","exit" then exit_message
  when "m","main" then main_menu
  when "l","list" then topic.list? ? error(topic) : topic_menu(topic.list)
  when "t","team" then topic.has_team? ? topic_menu(topic.team) : error(topic)
  else
    output = topic.valid_input?(input.to_i)
    output ? topic_menu(output) : error(topic)
  end
end