135 lines
4.5 KiB
Ruby
135 lines
4.5 KiB
Ruby
module Public
|
|
module LiveHelper
|
|
def live_score_sets_label(score_state, match = nil)
|
|
return nil unless score_state
|
|
|
|
board = match&.effective_board_type || score_state.effective_board_type
|
|
case board
|
|
when "basket", "timed"
|
|
live_score_period_label(match, score_state)
|
|
when "timer"
|
|
t("score.timer_label")
|
|
when "generic"
|
|
t("score.generic_label")
|
|
else
|
|
t("score.sets_label", set: score_state.current_set, home: score_state.home_sets, away: score_state.away_sets)
|
|
end
|
|
end
|
|
|
|
def live_score_period_label(match, score_state)
|
|
return t("score.fallback") unless score_state
|
|
|
|
score_state.current_period_label
|
|
end
|
|
|
|
def live_score_partials_label(score_state)
|
|
return nil unless score_state
|
|
return nil unless score_state.effective_board_type.in?(%w[volley racket])
|
|
|
|
partials = Array(score_state.set_partials)
|
|
return nil if partials.empty?
|
|
|
|
partials.map { |p| format_set_partial_entry(p) }.join(" · ")
|
|
end
|
|
|
|
def live_scheduled_label(datetime)
|
|
return nil unless datetime
|
|
|
|
datetime.in_time_zone.strftime(t("score.scheduled_date_format"))
|
|
end
|
|
|
|
def live_scheduled_relative(datetime)
|
|
return nil unless datetime
|
|
|
|
if datetime.to_date == Time.zone.today
|
|
t("score.scheduled_today", time: datetime.strftime("%H:%M"))
|
|
elsif datetime.to_date == Time.zone.tomorrow
|
|
t("score.scheduled_tomorrow", time: datetime.strftime("%H:%M"))
|
|
else
|
|
live_scheduled_label(datetime)
|
|
end
|
|
end
|
|
|
|
def live_match_card_heading(match, link_team: true)
|
|
team = match.team
|
|
club_name = team.club&.name.presence || t("score.default_club_name")
|
|
if match.tournament_match?
|
|
tournament = match.tournament
|
|
heading_name = tournament&.name.presence || club_name
|
|
matchup = match.matchup_label
|
|
return content_tag(:h3, class: "live-card__title") do
|
|
safe_join([
|
|
content_tag(:span, heading_name, class: "live-card__club"),
|
|
content_tag(:span, matchup, class: "live-card__matchup")
|
|
])
|
|
end
|
|
end
|
|
|
|
team_slug = team.respond_to?(:slug) ? team.slug : nil
|
|
team_label = if link_team && team_slug.present?
|
|
link_to(team.name, public_team_page_path(team_slug), class: "live-card__team-link")
|
|
else
|
|
team.name
|
|
end
|
|
content_tag(:h3, class: "live-card__title") do
|
|
safe_join([
|
|
content_tag(:span, club_name, class: "live-card__club"),
|
|
content_tag(:span, safe_join([team_label, " vs ", match.opponent_name]), class: "live-card__matchup")
|
|
])
|
|
end
|
|
end
|
|
|
|
def live_match_page_heading(match)
|
|
if match.tournament_match?
|
|
tournament = match.tournament
|
|
club_name = tournament&.name.presence || match.team.club&.name.presence || t("score.default_club_name")
|
|
return content_tag(:div, class: "live-page-heading") do
|
|
safe_join([
|
|
content_tag(:p, club_name, class: "live-page-heading__club"),
|
|
content_tag(:h1, match.matchup_label, class: "live-page-heading__matchup")
|
|
])
|
|
end
|
|
end
|
|
|
|
team = match.team
|
|
club_name = team.club&.name.presence || t("score.default_club_name")
|
|
content_tag(:div, class: "live-page-heading") do
|
|
safe_join([
|
|
content_tag(:p, club_name, class: "live-page-heading__club"),
|
|
content_tag(:h1, "#{team.name} vs #{match.opponent_name}", class: "live-page-heading__matchup")
|
|
])
|
|
end
|
|
end
|
|
|
|
def live_score_points_label(match, score_state)
|
|
return t("score.fallback") unless score_state
|
|
|
|
board = match.effective_board_type
|
|
home = case board
|
|
when "basket", "timed" then score_state.basket_home_score
|
|
else score_state.home_points
|
|
end
|
|
away = case board
|
|
when "basket", "timed" then score_state.basket_away_score
|
|
else score_state.away_points
|
|
end
|
|
|
|
t("score.points_label", team: match.home_display_name, home: home, away: away, opponent: match.away_display_name)
|
|
end
|
|
|
|
private
|
|
|
|
def format_set_partial_entry(partial)
|
|
data = partial.respond_to?(:with_indifferent_access) ? partial.with_indifferent_access : partial
|
|
set_no = data[:set] || data["set"]
|
|
home = data[:home] || data["home"]
|
|
away = data[:away] || data["away"]
|
|
if set_no.present?
|
|
t("score.partial_entry", set: set_no, home: home, away: away)
|
|
else
|
|
t("score.partial_entry_no_number", home: home, away: away)
|
|
end
|
|
end
|
|
end
|
|
end
|