module SportsReport
SportsReport โ IRC card formatting for !sports replies. Public: build, error, usage Tests: test/lib/sports_report_test.rb
Constants
- SOURCE
- TAG
Public Instance Methods
Source
# File lib/sports_report.rb, line 16 def build(sport:, match:, commentary_lines:) title = heading_title(sport: sport, match: match) footer = [match["status"].to_s, SOURCE].reject(&:empty?) IrcReply.card( tag: TAG, title: title, body_lines: commentary_lines, footer_parts: footer ) end
Source
# File lib/sports_report.rb, line 48 def display_score(value) text = value.to_s.strip return "-" if text.empty? || text == "null" text end
Source
# File lib/sports_report.rb, line 55 def error(message) IrcReply.error(tag: TAG, message: message) end
Source
# File lib/sports_report.rb, line 28 def heading_title(sport:, match:) home = match["home"].to_s away = match["away"].to_s home_score = display_score(match["home_score"]) away_score = display_score(match["away_score"]) competition = match["competition"].to_s scoreline = if numeric_scores?(home_score, away_score) "#{home} #{home_score}โ#{away_score} #{away}" else "#{home} #{home_score} โ #{away} #{away_score}" end parts = ["#{sport} ยท #{scoreline}"] parts << competition unless competition.empty? parts.join(" ยท ") end
Source
# File lib/sports_report.rb, line 44 def numeric_scores?(home_score, away_score) [home_score, away_score].all? { |score| score.match?(/\A\d+\z/) } end
Source
# File lib/sports_report.rb, line 59 def usage IrcReply.card( tag: TAG, title: "live sports commentary", body_lines: [ "Usage: !sports <#{SportsSport.usage_hint}> [country]", "Default region from !bot option set location (e.g. australia, uk, usa)" ], footer_parts: [SOURCE] ) end