class FifaRankings::CLI

Public Instance Methods

call() click to toggle source
# File lib/fifa_rankings/cli.rb, line 3
def call
  welcome
  get_teams
  list
  details
  goodbye
end
details() click to toggle source
# File lib/fifa_rankings/cli.rb, line 41
def details
  input = nil
  while input != "exit"
    puts ""
    puts ""
    puts "Enter the rank or name of the team that you would like more info on, type 'list' to see whole list, or type 'exit' to leave"
    input = gets.chomp.downcase

    if input.to_i.between?(1,FifaRankings::Team.all.size) || FifaRankings::Team.find_by_name(input)
      print_team(input)
    elsif input == "list"
      list
    elsif input != "exit"
      puts ""
      puts "Incorrect input, please try again."
    end

  end
end
get_teams() click to toggle source
# File lib/fifa_rankings/cli.rb, line 23
def get_teams
  teams = FifaRankings::Scraper.scrape_rankings_page('https://en.wikipedia.org/wiki/FIFA_Women%27s_World_Rankings')
  FifaRankings::Team.create_from_array(teams)
end
goodbye() click to toggle source
# File lib/fifa_rankings/cli.rb, line 17
def goodbye
  puts ""
  puts "Goodbye! Come back to see the updated rankings soon."
end
list() click to toggle source
# File lib/fifa_rankings/cli.rb, line 28
def list
  format = '%-6s %-14s %-10s'

  puts ""
  puts "FIFA Women's World Rankings".upcase
  puts "---------------------------"
  puts ""
  puts format % ["RANK", "TEAM", "CHANGE"]
  FifaRankings::Team.sort_by_rank.each.with_index(1) do |team, i|
    puts format % [i, team.name, team.movement]
  end
end
print_team(input) click to toggle source
welcome() click to toggle source
# File lib/fifa_rankings/cli.rb, line 11
def welcome
  puts ""
  puts "Welcome!"
  puts "Retrieving FIFA data..."
end