Class: Leaderbrag::CLI
- Inherits:
-
Thor
- Object
- Thor
- Leaderbrag::CLI
- Defined in:
- lib/leaderbrag/cli.rb
Overview
A CLI for Leaderbrag
Class Method Summary collapse
Instance Method Summary collapse
- #board ⇒ Object
- #find ⇒ Object
-
#initialize(args = [], local_options = {}, config = {}) ⇒ CLI
constructor
A new instance of CLI.
- #is?(team_id) ⇒ Boolean
Constructor Details
#initialize(args = [], local_options = {}, config = {}) ⇒ CLI
Returns a new instance of CLI.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/leaderbrag/cli.rb', line 18 def initialize(args = [], = {}, config = {}) super if ENV['XMLSTATS_CONTACT_INFO'].nil? warn 'Please set XMLSTATS_CONTACT_INFO environment variable.' exit 60 elsif ENV['XMLSTATS_API_KEY'].nil? warn 'Please set XMLSTATS_API_KEY environment variable' exit 70 end end |
Class Method Details
.exit_on_failure ⇒ Object
13 14 15 |
# File 'lib/leaderbrag/cli.rb', line 13 def self.exit_on_failure true end |
Instance Method Details
#board ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/leaderbrag/cli.rb', line 45 def board populate puts 'Team ID Win% W L Rank League Rank Div Rank GB Streak' puts '-'.ljust(77, '-') teams = @leader.filter([:sort_by_league], [:sort_by_division], [:only_league], [:only_division]) teams.each do |team| puts team.team_id.ljust(22) + team.win_percentage.ljust(6) + team.won.to_s.ljust(4) + team.lost.to_s.ljust(@leader.overall_rank(team) < 10 ? 5 : 4) + @leader.overall_rank(team).to_s.ljust(@leader.overall_rank(team) < 10 ? 7 : 8) + team.conference.ljust(@leader.league_rank(team) < 10 ? 7 : 6) + @leader.league_rank(team).to_s.ljust(@leader.league_rank(team) < 10 ? 5 : 6) + team.division.ljust(5) + team.rank.to_s.ljust(team.games_back < 10 ? 5 : 4) + team.games_back.to_s.ljust(team.games_back < 10 ? 7 : 8) + team.streak.to_s end end |
#find ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/leaderbrag/cli.rb', line 80 def find if ![:division].nil? && [:league].nil? warn 'League must be specified.' exit 80 end populate s_league = ([:league].nil? ? nil : [:league]) s_division = ([:division].nil? ? nil : [:division]) teams = @leader.filter(![:league].nil?, ![:division].nil?, s_league, s_division) myteam = teams[0] brag(myteam, false, [:stats]) end |
#is?(team_id) ⇒ Boolean
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/leaderbrag/cli.rb', line 108 def is?(team_id) populate myteam = @leader.team(team_id) if myteam.nil? warn "No such team with ID '#{team_id}'" exit 50 end brag(myteam, [:quiet], [:stats]) if @leader.overall_leader?(myteam) || ([:league] && @leader.league_leader?(myteam)) || ([:division] && @leader.division_leader?(myteam)) exit 0 else exit myteam.rank end end |