Class: FifaRankings::CLI
- Inherits:
-
Object
- Object
- FifaRankings::CLI
- Defined in:
- lib/fifa_rankings/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #details ⇒ Object
- #get_teams ⇒ Object
- #goodbye ⇒ Object
- #list ⇒ Object
- #print_team(input) ⇒ Object
- #welcome ⇒ Object
Instance Method Details
#call ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/fifa_rankings/cli.rb', line 3 def call welcome get_teams list details goodbye end |
#details ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 ⇒ Object
23 24 25 26 |
# 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 ⇒ Object
17 18 19 20 |
# File 'lib/fifa_rankings/cli.rb', line 17 def goodbye puts "" puts "Goodbye! Come back to see the updated rankings soon." end |
#list ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# 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) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fifa_rankings/cli.rb', line 61 def print_team(input) team = FifaRankings::Team.find_by_rank(input.to_i) || FifaRankings::Team.find_by_name(input) attributes = FifaRankings::Scraper.scrape_team_page('https://en.wikipedia.org' + team.url) team.add_attributes(attributes) puts "" puts " #{team.name.upcase}" puts "-" * 78 #74 is the longest line + 2 on either side for spacing puts " Rank:" + " #{team.rank}" puts " Points:" + " #{team.points}" puts " Confederation:" + " #{team.confederation}" puts " Head coach:" + " #{team.head_coach}" puts " Team captain(s):" + " #{team.captain}" puts " Top scorer(s):" + " #{team.top_scorer}" puts " Most caps:" + " #{team.most_caps}" puts "-" * 78 end |
#welcome ⇒ Object
11 12 13 14 15 |
# File 'lib/fifa_rankings/cli.rb', line 11 def welcome puts "" puts "Welcome!" puts "Retrieving FIFA data..." end |