Class: NBA::CLI
- Inherits:
-
Thor
- Object
- Thor
- NBA::CLI
- Includes:
- Display, Formatters, Helpers
- Defined in:
- lib/nba/cli.rb,
lib/nba/cli/display.rb,
lib/nba/cli/helpers.rb,
lib/nba/cli/formatters.rb,
lib/nba/cli/display/player_display.rb,
lib/nba/cli/formatters/game_formatters.rb,
lib/nba/cli/formatters/team_formatters.rb,
lib/nba/cli/formatters/time_formatters.rb,
lib/nba/cli/formatters/player_formatters.rb,
lib/nba/cli/formatters/leaders_formatters.rb,
lib/nba/cli/formatters/standings_formatters.rb
Overview
Command-line interface for the NBA gem
Defined Under Namespace
Modules: Display, Formatters, Helpers
Constant Summary collapse
- CATEGORY_MAP =
Mapping of category names and abbreviations to Leaders constants
{ "PTS" => "PTS", "POINTS" => "PTS", "REB" => "REB", "REBOUNDS" => "REB", "AST" => "AST", "ASSISTS" => "AST", "STL" => "STL", "STEALS" => "STL", "BLK" => "BLK", "BLOCKS" => "BLK", "FG_PCT" => "FG_PCT", "FG3_PCT" => "FG3_PCT", "FT_PCT" => "FT_PCT" }.freeze
Constants included from Helpers
Helpers::CONFERENCE_MAP, Helpers::ET_OFFSET_SECONDS
Constants included from Formatters
Constants included from Formatters::TeamFormatters
Formatters::TeamFormatters::DIVISIONS, Formatters::TeamFormatters::EAST
Constants included from Formatters::TimeFormatters
Formatters::TimeFormatters::ET_TIME_PATTERN
Class Method Summary collapse
-
.exit_on_failure? ⇒ Boolean
Returns whether Thor should exit on failure.
Instance Method Summary collapse
-
#games ⇒ void
Retrieves and displays games for a specified date.
-
#leaders(category_name = "PTS") ⇒ void
Displays league leaders for a statistical category.
-
#player(name) ⇒ void
Searches for players by name.
-
#roster(team_name) ⇒ void
Displays roster for a team.
-
#schedule(team_name) ⇒ void
Displays schedule for a team.
-
#standings ⇒ void
Displays current league standings.
-
#teams(name = nil) ⇒ void
Lists all teams or searches for teams by name.
-
#version ⇒ void
Displays version information.
Methods included from Helpers
#eastern_time_date, #fetch_conference_standings, #fetch_games, #fetch_standings, #fetch_team_roster, #fetch_team_schedule, #filter_teams, #find_team_by_name, #normalize_conference, #parse_date, #parse_date_string, #resolve_leader_category
Methods included from Display
#display_games, #display_leaders, #display_players_list, #display_roster, #display_schedule, #display_standings, #display_team, #display_team_championships, #display_team_conference, #display_team_division, #display_team_names, #display_team_roster, #display_teams, #fetch_team_year_stats
Methods included from Display::PlayerDisplay
#display_player, #display_player_draft, #display_player_physical, #display_players
Methods included from Formatters
#center, #format_label, #format_multiline_label, #max_length
Methods included from Formatters::PlayerFormatters
#format_detailed_roster_player, #format_draft_info, #format_jersey_number, #format_player_result, #format_position
Methods included from Formatters::LeadersFormatters
#calculate_leader_widths, #format_leader_row
Methods included from Formatters::StandingsFormatters
#calculate_standings_widths, #format_standing_row
Methods included from Formatters::GameFormatters
#calculate_game_widths, #determine_opponent, #format_game_row, #format_game_scores, #format_game_status, #format_game_teams, #format_schedule_game, #score_widths
Methods included from Formatters::TeamFormatters
#championship_year?, #conference_name, #division_for_team, #division_name, #team_nickname
Methods included from Formatters::TimeFormatters
#build_et_time, #convert_et_to_local, #convert_to_24h, #format_local_time, #local_time_zone_abbr, #parse_et_time
Class Method Details
.exit_on_failure? ⇒ Boolean
Returns whether Thor should exit on failure
37 38 39 |
# File 'lib/nba/cli.rb', line 37 def self.exit_on_failure? true end |
Instance Method Details
#games ⇒ void
This method returns an undefined value.
Retrieves and displays games for a specified date
50 51 52 53 54 |
# File 'lib/nba/cli.rb', line 50 def games date = parse_date([:date]) games_list = fetch_games(date) games_list.empty? ? say("No games found for #{date}") : display_games(games_list) end |
#leaders(category_name = "PTS") ⇒ void
This method returns an undefined value.
Displays league leaders for a statistical category
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/nba/cli.rb', line 121 def leaders(category_name = "PTS") category = resolve_leader_category(category_name, CATEGORY_MAP) leaders_list = if [:season] Leaders.find(category: category, limit: .fetch(:limit), season: .fetch(:season)) else Leaders.find(category: category, limit: .fetch(:limit)) end display_leaders(leaders_list, category_name) end |
#player(name) ⇒ void
This method returns an undefined value.
Searches for players by name
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/nba/cli.rb', line 84 def player(name) pattern = Regexp.new(name, Regexp::IGNORECASE) matching = Players.all.select { |p| pattern.match?(p.full_name) } if matching.empty? say("No player found with name '#{name}'") elsif matching.one? matching.each { |p| display_player(p) } else display_players(matching) end end |
#roster(team_name) ⇒ void
This method returns an undefined value.
Displays roster for a team
162 163 164 165 166 167 168 169 170 |
# File 'lib/nba/cli.rb', line 162 def roster(team_name) team = find_team_by_name(team_name) if team roster_list = fetch_team_roster(team) display_roster(roster_list, team) else say("No team found with name '#{team_name}'") end end |
#schedule(team_name) ⇒ void
This method returns an undefined value.
Displays schedule for a team
142 143 144 145 146 147 148 149 150 |
# File 'lib/nba/cli.rb', line 142 def schedule(team_name) team = find_team_by_name(team_name) if team schedule_list = fetch_team_schedule(team) display_schedule(schedule_list, team) else say("No team found with name '#{team_name}'") end end |
#standings ⇒ void
This method returns an undefined value.
Displays current league standings
106 107 108 |
# File 'lib/nba/cli.rb', line 106 def standings display_standings(fetch_standings) end |
#teams(name = nil) ⇒ void
This method returns an undefined value.
Lists all teams or searches for teams by name
66 67 68 69 70 71 72 73 |
# File 'lib/nba/cli.rb', line 66 def teams(name = nil) matching_teams = filter_teams(name) if matching_teams.empty? say("No team found with name '#{name}'") else display_teams(matching_teams, .fetch(:roster), detailed: name) end end |
#version ⇒ void
This method returns an undefined value.
Displays version information
180 181 182 |
# File 'lib/nba/cli.rb', line 180 def version say("nba #{VERSION}") end |