Class: Pizza
- Inherits:
-
Object
- Object
- Pizza
- Defined in:
- lib/pizza.rb,
lib/pizza.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#allergen_warning ⇒ Object
Returns the value of attribute allergen_warning.
-
#category_id ⇒ Object
Returns the value of attribute category_id.
-
#crust ⇒ Object
Returns the value of attribute crust.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#size ⇒ Object
Returns the value of attribute size.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #available_crusts ⇒ Object
- #available_sizes ⇒ Object
-
#initialize(element) ⇒ Pizza
constructor
A new instance of Pizza.
- #list_item ⇒ Object
- #params ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(element) ⇒ Pizza
Returns a new instance of Pizza.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 |
Instance Attribute Details
#allergen_warning ⇒ Object
Returns the value of attribute allergen_warning.
17 18 19 |
# File 'lib/pizza.rb', line 17 def allergen_warning @allergen_warning end |
#category_id ⇒ Object
Returns the value of attribute category_id.
17 18 19 |
# File 'lib/pizza.rb', line 17 def category_id @category_id end |
#crust ⇒ Object
Returns the value of attribute crust.
18 19 20 |
# File 'lib/pizza.rb', line 18 def crust @crust end |
#description ⇒ Object
Returns the value of attribute description.
17 18 19 |
# File 'lib/pizza.rb', line 17 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
17 18 19 |
# File 'lib/pizza.rb', line 17 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
17 18 19 |
# File 'lib/pizza.rb', line 17 def name @name end |
#size ⇒ Object
Returns the value of attribute size.
18 19 20 |
# File 'lib/pizza.rb', line 18 def size @size end |
#url ⇒ Object
Returns the value of attribute url.
17 18 19 |
# File 'lib/pizza.rb', line 17 def url @url end |
Instance Method Details
#available_crusts ⇒ Object
54 55 56 57 58 59 |
# 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 ⇒ Object
47 48 49 50 51 52 |
# 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 ⇒ Object
70 71 72 73 74 75 76 |
# 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 ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/pizza.rb', line 61 def params { "shohinC1" => id, "categoryC" => category_id, "sizeC" => size.value, "crustC" => crust.value } end |
#valid? ⇒ Boolean
43 44 45 |
# File 'lib/pizza.rb', line 43 def valid? url != nil end |