Class: NewGames::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



5
6
7
8
9
# File 'lib/new_games/cli.rb', line 5

def call
  Game.scrape_all
  list 
  menu
end

#listObject



11
12
13
14
15
16
17
18
# File 'lib/new_games/cli.rb', line 11

def list 
  puts ""
  puts "************* Xbox One Upcoming Games ****************"
  puts "" 
  Game.all.each.with_index(1) do |game, i| 
    puts "#{i}. #{game.title}"
  end
end

list end



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/new_games/cli.rb', line 20

def menu
  input = nil 
  while input != "exit"
    puts "----------------------------------------------"
    puts "Which game would you like to know more about?"
    puts "" 
    puts "Type the number that matches the game"
    puts ""
    puts "Type list to see the list again"
    puts "Type exit to end the program"
    puts "----------------------------------------------"
    input = gets.strip
    if input == "list"
      list
    elsif input.to_i.between?(1, Game.all.size)
      game = Game.find(input)
      puts "   Name: #{game.title}"
      puts "   Date: #{game.date}"
      puts "   Price: #{game.price}"
      puts "   Publisher: #{game.publisher}"
    elsif !input.to_i.between?(1, Game.all.size)
        puts "Invalid number. Please type a valid number"
    else
      "goodbye"
    end
  end
  puts "Come back to see a list of upcoming Xbox One games"
end