class Standings::CLI

Public Instance Methods

record_user_selection_and_show_results!() click to toggle source
# File lib/standings/cli.rb, line 3
def record_user_selection_and_show_results!
  league_selection = accept_input

  if league_selection
    handle_valid_league_selection(league_selection)
  else
    handle_help_message
  end
end

Private Instance Methods

accept_input() click to toggle source
# File lib/standings/cli.rb, line 15
    def accept_input
      opts = Trollop::options do
        version <<-EOS
      ⚽  Standings
      Version 1.0 | September 2016
      Scott Luptowski | @scottluptowski
      EOS
        banner <<-EOS
      \n⚽  Standings is a command line gem which lets users check the current standings in a number of European football/soccer leagues.
      Usage:
      \n
      EOS
        opt :epl, "šŸ‡¬šŸ‡§  English Premier League", short: :e
        opt :championship, "šŸ‡¬šŸ‡§  English Championship", short: :c
        opt :league1, "šŸ‡¬šŸ‡§  English League One", short: :o
        opt :league2, "šŸ‡¬šŸ‡§  English League Two", short: :t
        opt :spl, "šŸ‡¬šŸ‡§  Scottish Premiership", short: :s
        opt :liga, "šŸ‡ŖšŸ‡ø  La Liga", short: :l
        opt :ligue, "šŸ‡«šŸ‡·  Ligue 1", short: :f
        opt :seriea, "šŸ‡®šŸ‡¹  Seria A", short: :i
        opt :bundesliga, "šŸ‡©šŸ‡Ŗ  Bundesliga", short: :d
      end

      opts.keys.detect { |k| opts[k] }
    end
handle_failure() click to toggle source
# File lib/standings/cli.rb, line 54
def handle_failure
  puts "⚽  There was an error retrieving the scores!"
end
handle_help_message() click to toggle source
# File lib/standings/cli.rb, line 50
def handle_help_message
  puts "⚽  Standings requires you to pass in the flag of a league. Run with --help for help."
end
handle_valid_league_selection(league_selection) click to toggle source
# File lib/standings/cli.rb, line 41
def handle_valid_league_selection(league_selection)
  begin
    results = TableFetcher.new(league_selection).call
    Displayer.new(results).display_table
  rescue TableFetcher::FetchError, TableFetcher::ParseError
    handle_failure
  end
end