class Pizza
Attributes
allergen_warning[RW]
category_id[RW]
crust[RW]
description[RW]
id[RW]
name[RW]
size[RW]
url[RW]
Public Class Methods
new(element)
click to toggle source
# File lib/pizza.rb, line 20 def initialize(element) return unless element["iname"] link = element["href"] parts = link.split("/") pizza_id = parts.pop category_id = parts.pop # some_other_number = parts.pop # TODO: figure out what this is description = element.css(".menu_itemList_item_text").first description = description.text if description allergen_warning = element.css(".js-menuSetHeight_allergen").first allergen_warning = allergen_warning.text if allergen_warning self.url = "https://order.dominos.jp#{link}" self.id = pizza_id # shohinC1 self.category_id = category_id # categoryC self.name = element["iname"] self.description = description self.allergen_warning = allergen_warning end
Public Instance Methods
available_crusts()
click to toggle source
# File lib/pizza.rb, line 54 def available_crusts @available_crusts ||= detail_page_content.css("#detail_selectCrust .m-input__radio").map do |option| Pizza::Crust.new(option) end end
available_sizes()
click to toggle source
# File lib/pizza.rb, line 47 def available_sizes @available_sizes ||= detail_page_content.css("#detail_selectSize .m-input__radio").map do |option| Pizza::Size.new(option) end end
list_item()
click to toggle source
# File lib/pizza.rb, line 70 def list_item allergen = allergen_warning || "" "#{name.colorize(:blue)} "\ "#{allergen.strip.colorize(:yellow)}\n "\ "#{description.gsub(",", ", ").gsub(")", ") ")}\n" end
params()
click to toggle source
# File lib/pizza.rb, line 61 def params { "shohinC1" => id, "categoryC" => category_id, "sizeC" => size.value, "crustC" => crust.value } end
valid?()
click to toggle source
# File lib/pizza.rb, line 43 def valid? url != nil end
Private Instance Methods
detail_page_content()
click to toggle source
# File lib/pizza.rb, line 80 def detail_page_content @detail_page_content ||= Nokogiri::HTML( Request.get(url, expect: :ok, failure: "Couldn't open pizza detail page").body ) end