module RedRoosterMenu
Constants
- PROMO_CATEGORY_PATTERN
- STYLE_TITLE
Public Instance Methods
Source
# File lib/red_rooster_menu.rb, line 82 def extract_category_items(category) Array(category["products"]).filter_map do |product| next unless product_visible?(product) product_item(product) end end
Source
# File lib/red_rooster_menu.rb, line 134 def format_item_line(item) if item[:price] && !item[:price].empty? "#{item[:name]} โ #{item[:price]}" else item[:name].to_s end end
Source
# File lib/red_rooster_menu.rb, line 142 def format_item_paragraphs(items, max_bytes: RedRoosterConfig::MENU_PARAGRAPH_MAX_BYTES, separator: ", ") entries = items.map { |item| format_item_line(item) } ParagraphFormat.build_paragraphs(entries, max_bytes: max_bytes, separator: separator) end
Source
# File lib/red_rooster_menu.rb, line 179 def format_not_found(location) header = IrcFormat.report_header(tag: "RR", title: location.to_s.strip, style: STYLE_TITLE) [ header, "Could not find a Red Rooster store near #{location}.", IrcFormat.report_footer("store lookup", "redrooster.com.au") ].join("\n") end
Source
# File lib/red_rooster_menu.rb, line 35 def format_price(cents) return nil if cents.nil? dollars = cents.to_f / 100.0 format("$%.2f", dollars) end
Source
# File lib/red_rooster_menu.rb, line 159 def format_report(store:, promo_items:, menu_items:) header = IrcFormat.report_header(tag: "RR", title: banner_title(store), style: STYLE_TITLE) lines = [header] lines.concat(format_section("--- Promos & Specials ---", promo_items)) lines.concat(format_section("--- Menu ---", menu_items)) if promo_items.empty? && menu_items.empty? lines << "No menu items found for this store." end promo_count = promo_items.length menu_count = menu_items.length footer_bits = [] footer_bits << "#{promo_count} promos" if promo_count.positive? footer_bits << "#{menu_count} items" if menu_count.positive? footer_bits << store[:slug] if store[:slug] && !store[:slug].empty? lines << IrcFormat.report_footer(*footer_bits, "redrooster.com.au") lines.join("\n") end
Source
# File lib/red_rooster_menu.rb, line 147 def format_section(title, items) return [] if items.empty? [title, *format_item_paragraphs(items)] end
Source
# File lib/red_rooster_menu.rb, line 90 def partition_items(categories, public_vouchers: [], user_vouchers: []) promo_items = [] menu_items = [] seen = {} Array(public_vouchers).each do |voucher| item = voucher_item(voucher) next if item[:name].empty? next if seen[item[:name].downcase] seen[item[:name].downcase] = true promo_items << item end Array(user_vouchers).each do |voucher| item = voucher_item(voucher) next if item[:name].empty? next if seen[item[:name].downcase] seen[item[:name].downcase] = true promo_items << item end Array(categories).each do |category| name = category["name"].to_s next if hidden_category?(name) items = extract_category_items(category) target = promo_category?(name) ? promo_items : menu_items items.each do |item| key = item[:name].downcase next if seen[key] seen[key] = true target << item end end { promo_items: promo_items.first(RedRoosterConfig::MAX_PROMO_ITEMS), menu_items: menu_items.first(RedRoosterConfig::MAX_MENU_ITEMS) } end
Source
# File lib/red_rooster_menu.rb, line 66 def product_item(product) { name: product["name"].to_s.strip, price: format_price(product["price"]), kind: :product } end
Source
# File lib/red_rooster_menu.rb, line 58 def product_visible?(product) return false if product["snoozed"] return false if product["visible"] == false name = product["name"].to_s.strip !name.empty? end
Source
# File lib/red_rooster_menu.rb, line 23 def promo_category?(name) text = name.to_s.strip return false if text.empty? return false if hidden_category?(text) text.match?(PROMO_CATEGORY_PATTERN) end
Source
# File lib/red_rooster_menu.rb, line 74 def voucher_item(voucher) { name: voucher["title"].to_s.strip, price: nil, kind: :voucher } end