Class: OwHeroesRoster::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/ow_heroes_roster/cli.rb

Instance Method Summary collapse

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ow_heroes_roster/cli.rb', line 5

def call
  puts "\nWELCOME TO THE OVERWATCH HEROES ROSTER GEM!".colorize(:green)
  puts "\n----***------ INSTRUCTIONS ------***----".colorize(:white)
  puts "\n1. Enter a hero's name to see their details.".colorize(:white)
  puts "2. To see the roster again, type 'roster'.".colorize(:white)
  puts "3. To exit the program, type 'exit'.".colorize(:white)
  puts "\n----------------------------------------".colorize(:white)
  Roster.scrape_roster_page
  list_heroes
  menu
end

#display_hero(input) ⇒ Object

display the details of the requested hero. do I want this here?



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ow_heroes_roster/cli.rb', line 42

def display_hero(input)
  #use a find by name method to get the right hero and then display the information
  if Hero.find_by_name(input)
    hero = Hero.find_by_name(input)
    hero.display_information
    menu
  else
    puts "\nSorry could not find a hero by that name. Please try again.".colorize(:green)
    menu
  end
end

#list_heroesObject

print the list of heroes scraped from the site



18
19
20
21
22
23
24
25
26
# File 'lib/ow_heroes_roster/cli.rb', line 18

def list_heroes
  puts "\n---***------  HEROES ------***---".colorize(:yellow)
  @heroes = Hero.all
  Hero.all.each do |hero|
    print " --- ".colorize(:magenta)
    puts "#{hero.name}".colorize(:white)
  end
  menu
end

ask user if they’d like to select a hero (by name or number?) for more details, reprint the list, or exit the program



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ow_heroes_roster/cli.rb', line 29

def menu
  print "\nWhat would you like to do? ".colorize(:green)
  input = gets.strip.upcase
  if input == 'ROSTER'
    list_heroes
  elsif input == 'EXIT'
    exit
  else
    display_hero(input)
  end
end