class Pubcrawl
Constants
- QUERIES
- STYLE_TITLE
Public Class Methods
Source
# File plugins/pubcrawl.rb, line 25 def self.find_places(location, fetch:) seen = {} places = [] QUERIES.each do |query| html = fetch.call("#{query} #{location} queensland") candidate = Beer.extract_best_place_from_ddg_html(html, location: location) next unless candidate next if seen[candidate.downcase] seen[candidate.downcase] = true places << candidate break if places.length >= 5 end places end
Source
# File plugins/pubcrawl.rb, line 43 def self.lookup(location, fetch: Beer.allocate.method(:fetch_html)) parsed = Beer.parse_location(location) return parsed[:error] if parsed[:error] places = find_places(parsed[:location], fetch: fetch) return "Could not find pubs near #{parsed[:location]}" if places.empty? header = IrcFormat.report_header(tag: "CRAWL", title: parsed[:location], style: STYLE_TITLE) lines = places.each_with_index.map { |place, index| "#{index + 1}. #{place}" } footer = IrcFormat.report_footer("#{places.length} stops") ([header] + lines + [footer]).join("\n") rescue StandardError "Could not build pub crawl for #{location}" end
Source
# File plugins/pubcrawl.rb, line 21 def self.usage_message 'Usage: !pubcrawl <town> — e.g. !pubcrawl "mount low"' end
Public Instance Methods
Source
# File plugins/pubcrawl.rb, line 58 def execute(m, location) themed_flood_safe_reply(m, self.class.lookup(location)) end