Class: Pizza

Inherits:
Object
  • Object
show all
Defined in:
lib/pizza.rb,
lib/pizza.rb

Defined Under Namespace

Classes: Crust, Size

Instance Attribute Summary collapse

Instance Method Summary collapse

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_warningObject

Returns the value of attribute allergen_warning.



17
18
19
# File 'lib/pizza.rb', line 17

def allergen_warning
  @allergen_warning
end

#category_idObject

Returns the value of attribute category_id.



17
18
19
# File 'lib/pizza.rb', line 17

def category_id
  @category_id
end

#crustObject

Returns the value of attribute crust.



18
19
20
# File 'lib/pizza.rb', line 18

def crust
  @crust
end

#descriptionObject

Returns the value of attribute description.



17
18
19
# File 'lib/pizza.rb', line 17

def description
  @description
end

#idObject

Returns the value of attribute id.



17
18
19
# File 'lib/pizza.rb', line 17

def id
  @id
end

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/pizza.rb', line 17

def name
  @name
end

#sizeObject

Returns the value of attribute size.



18
19
20
# File 'lib/pizza.rb', line 18

def size
  @size
end

#urlObject

Returns the value of attribute url.



17
18
19
# File 'lib/pizza.rb', line 17

def url
  @url
end

Instance Method Details

#available_crustsObject



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_sizesObject



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_itemObject



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

#paramsObject



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

Returns:

  • (Boolean)


43
44
45
# File 'lib/pizza.rb', line 43

def valid?
  url != nil
end