Class: EplCliGem::CLI
- Inherits:
-
Object
- Object
- EplCliGem::CLI
- Defined in:
- lib/epl_cli_gem/cli.rb
Instance Method Summary collapse
- #ask_for_team(input) ⇒ Object
- #bye ⇒ Object
- #call ⇒ Object
- #list_teams ⇒ Object
- #print_team(team) ⇒ Object
- #spell_check ⇒ Object
- #start ⇒ Object
Instance Method Details
#ask_for_team(input) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/epl_cli_gem/cli.rb', line 47 def ask_for_team(input) if input.downcase == 'exit' bye elsif input.to_i == 0 team = @teams.find{|team| team.name.downcase == input.downcase} team != nil ? print_team(team) : spell_check elsif input.to_i.between?(1, 20) team = @teams.find{|team| team.rank == input} print_team(team) else spell_check end end |
#bye ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/epl_cli_gem/cli.rb', line 95 def bye for_clu = "For Clu".colorize(:red).on_blue b_and_C = "b and C".colorize(:light_white).on_blue ountry = "ountry".colorize(:red).on_blue puts "#{for_clu}#{b_and_C}#{ountry}" puts "" sleep 1 abort end |
#call ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/epl_cli_gem/cli.rb', line 3 def call puts "" puts "Welcome to the English Premier League CLI gem\n\n".colorize(:cyan) puts "If the output looks messy please\nmake sure your CLI is long enough.\n\n".colorize(:light_red).underline EplCliGem::Team.make_teams # Priming set here to give user time to read preceding output. start end |
#list_teams ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/epl_cli_gem/cli.rb', line 30 def list_teams rows = [] @teams ||= EplCliGem::Team.sorted @teams.each.with_index(1) do |team, i| rows << [i, team.name, team.games_played, team.goal_diff, team.points] end table = Terminal::Table.new :title => "Current League Table", :headings => ['POSN', 'Team', 'PL', 'GD', 'Pts'], :rows => rows table.align_column 0, :center puts table puts "" end |
#print_team(team) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/epl_cli_gem/cli.rb', line 65 def print_team(team) rows = [] rows << ['Position', team.rank] rows << ['Points', team.points] rows << ['Games Played', team.games_played] rows << ['Won', team.won] rows << ['Drawn', team.drawn] rows << ['Lost', team.lost] rows << ['Goal Difference', team.goal_diff] table = Terminal::Table.new :title => "#{team.name}", :rows => rows puts "" puts table match = [] match << [team.team_1, team.match_time, team.team_2] next_match = Terminal::Table.new :title => "Next Match\n#{team.match_date}", :rows => match next_match.align_column 0, :center next_match.align_column 1, :center next_match.align_column 2, :center puts next_match team.club_news end |
#spell_check ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/epl_cli_gem/cli.rb', line 105 def spell_check puts "" puts "Invalid Entry, please check spelling".on_red puts "or select a number between 1 and 20.".on_red puts "" sleep 2 start end |
#start ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/epl_cli_gem/cli.rb', line 11 def start eXit = "EXIT".colorize(:red).underline yes = "Yes".colorize(:light_cyan) list_teams puts "You can always exit the program by typing #{eXit}.\n\n" puts "Which team would you like more information on?" puts "Please select by team name or current position." puts "(Not case sensitive)".colorize(:red) input = gets.strip ask_for_team(input) puts "Type #{yes} to learn more about another team\n otherwise enter any other key to #{eXit}." input = gets.strip input.downcase == 'y' || input.downcase == 'yes' ? start : bye end |