Skip to content

Commit

Permalink
use a direct link for records in standings
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Hoffman <[email protected]>
  • Loading branch information
Fustrate committed May 31, 2024
1 parent b400104 commit c81c957
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/baseballbot/templates/components/league_standings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,31 @@ def initialize(subreddit, teams)
def to_s
rows = %w[West Central East].map do |division|
@teams.select { _1.team.dig('division', 'name')[division] }
.map { team_cell(_1) }
.map { "#{team_link(_1)} [#{team_record(_1)}]](/r/#{subreddit_name(_1)})]" }
end.transpose

table(headers: [['West', :center], ['Central', :center], ['East', :center]], rows:)
end

protected

def team_cell(team)
return "#{team_link(team)} [**#{team.wins}-#{team.losses}**][#{team.abbreviation}]" if team.division_champ?

return "#{team_link(team)} [*#{team.wins}-#{team.losses}*][#{team.abbreviation}]" if team.wildcard_champ?

"#{team_link(team)} [#{team.wins}-#{team.losses}][#{team.abbreviation}]"
end
def team_cell(team) = "#{team_link(team)} #{team_record(team)}"

def team_link(team)
return "[#{team.abbreviation}][#{team.abbreviation}]" unless team.wildcard_position

"[#{team.abbreviation}](/r/#{subreddit_name(team)} \"WC#{team.wildcard_position}\")"
end

# We have to use a direct link instead of [][ABBR] because those links have #flair
def team_record(team)
return "**#{team.wins}-#{team.losses}**" if team.division_champ?

return "*#{team.wins}-#{team.losses}*" if team.wildcard_champ?

"#{team.wins}-#{team.losses}"
end

def subreddit_name(team) = @subreddit.code_to_subreddit_name(team.abbreviation)

# @!group Wildcards
Expand Down

0 comments on commit c81c957

Please sign in to comment.