class Lotto
Constants
- STYLE_TITLE
- URL
Public Class Methods
Source
# File plugins/lotto.rb, line 28 def self.lookup(fetch: RabbotHttp.method(:fetch)) html = fetch.call(URL) results = parse_results(html) header = IrcFormat.report_header(tag: "LOTTO", title: "latest draws", style: STYLE_TITLE) body = results.empty? ? "Could not parse lottery results — check ozlotteries.com" : results.join("\n") footer = IrcFormat.report_footer("Oz Lotteries") [header, body, footer].join("\n") rescue StandardError "Could not fetch lottery results" end
Source
# File plugins/lotto.rb, line 22 def self.parse_results(html) doc = Nokogiri::HTML(html.to_s) lines = doc.css("h2, h3, .game-title, .result-numbers, li").map { |node| node.text.squeeze(" ").strip } lines.reject(&:empty?).grep(/\d/).first(6) end
Public Instance Methods
Source
# File plugins/lotto.rb, line 39 def execute(m) themed_flood_safe_reply(m, self.class.lookup) end