class Ozb
Constants
- HOME_URL
- STYLE_BANNER
- USER_AGENT
Public Class Methods
Source
# File plugins/ozb.rb, line 28 def self.absolute_url(path) value = path.to_s.strip return value if value.start_with?("http://", "https://") "https://www.ozbargain.com.au#{value}" end
Source
# File plugins/ozb.rb, line 64 def self.build_report(deals) return "No bargains found" if deals.empty? [ report_banner, *deals.each_with_index.map { |deal, index| format_deal_line(index + 1, **deal) }, report_footer(deals.length) ].join("\n") end
Source
# File plugins/ozb.rb, line 51 def self.format_deal_line(index, title:, url:) "#{index}. #{title} (#{url})" end
Source
# File plugins/ozb.rb, line 74 def self.gather_bargains(fetch:) html = fetch.call(HOME_URL) deals = parse_deals(html) build_report(deals) rescue StandardError "Could not fetch bargains" end
Source
# File plugins/ozb.rb, line 35 def self.parse_deals(html) doc = Nokogiri.HTML(html.to_s) doc.css(".node-ozbdeal").filter_map do |node| link = node.at_css("h2.title a") next unless link title = link.text.to_s.strip href = link["href"].to_s.strip next if title.empty? || href.empty? { title: title, url: absolute_url(href) } end rescue StandardError [] end
Public Instance Methods
Source
# File plugins/ozb.rb, line 90 def execute(m) themed_flood_safe_reply(m, gather_bargains) end
Source
# File plugins/ozb.rb, line 86 def fetch_page(url) RabbotHttp.fetch(url, user_agent: USER_AGENT) end
Source
# File plugins/ozb.rb, line 82 def gather_bargains(fetch: method(:fetch_page)) self.class.gather_bargains(fetch: fetch) end