Class: CliEplTable::CLI

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

Class Method Summary collapse

Class Method Details

.callObject



4
5
6
7
8
# File 'lib/cli_epl_table/cli.rb', line 4

def self.call
  show_table
  table
  goodbye
end

.goodbyeObject

exit message for when the user types exit



62
63
64
# File 'lib/cli_epl_table/cli.rb', line 62

def self.goodbye
  puts "Thanks for checking out the standings!".cyan
end

.show_tableObject

show the full table at startup



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

def self.show_table
  puts "English Premier League Table:".blue
  # puts "1. Man City - points"
  # puts "2. Man U - points"
  @teams = CliEplTable::Team.all
  @teams.each do |team|
    puts "#{team.position}. ".yellow + "#{team.name}".blue + " - " + "#{team.points} points".red
  end
end

.tableObject

take user input showing the table or team they enter until they exit



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
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cli_epl_table/cli.rb', line 22

def self.table
  input = nil
  while input != "exit"
    puts "-------------------------------------------------".white
    puts "Enter the position number(1-20) of the team you would like to see in depth, type table to show the table again, or type exit to exit:".cyan
    input = gets.strip.downcase

    if input.to_i > 0 && input.to_i < 21
      team = @teams[input.to_i - 1]
      puts "-------------------------------------------------".white
      puts "Team Name:          ".blue + "#{team.name}".light_red
      if team.position == "1"
        puts "Position:           ".blue + "#{team.position}st place".light_red
      elsif team.position == "2"
        puts "Position:           ".blue + "#{team.position}nd place".light_red
      elsif team.position == "3"
        puts "Position:           ".blue + "#{team.position}rd place".light_red
      else
        puts "Position:           ".blue + "#{team.position}th place".light_red
      end
      puts "Games Played:       ".blue + "#{team.games_played}".light_red
      puts "Games Won:          ".blue + "#{team.games_won}".light_red
      puts "Games Drawn:        ".blue + "#{team.games_drawn}".light_red
      puts "Games Lost:         ".blue + "#{team.games_lost}".light_red
      puts "Goals For:          ".blue + "#{team.goals_for}".light_red
      puts "Goals Against:      ".blue + "#{team.goals_against}".light_red
      puts "Goal Differential:  ".blue + "#{team.goal_differential}".light_red
      puts "Points:             ".blue + "#{team.points}".light_red
    elsif input == "table"
      puts "-------------------------------------------------".white
      show_table
    elsif input == "exit"
    else
      puts "-------------------------------------------------".white
      puts "Invalid entry, enter a valid position number, table, or exit.".red
    end
  end
end