Class: Side

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

Defined Under Namespace

Classes: Combo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ Side

Returns a new instance of Side.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/side.rb', line 21

def initialize(element)
  return unless element["iname"]

  link = element["href"]
  parts = link.split("/")
  side_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 = side_id # shohinC
  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.



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

def allergen_warning
  @allergen_warning
end

#category_idObject

Returns the value of attribute category_id.



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

def category_id
  @category_id
end

#comboObject

Returns the value of attribute combo.



19
20
21
# File 'lib/side.rb', line 19

def combo
  @combo
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#available_combosObject



52
53
54
55
56
57
58
59
# File 'lib/side.rb', line 52

def available_combos
  @available_combos ||=
    detail_page_content.css(".m-section_item__changeSide .m-input__radio").map do |option|
      Side::Combo.new(option)
    end

  @available_combos.sort_by! { |cmb| cmb.default ? 0 : 1 }
end

#customizable?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/side.rb', line 48

def customizable?
  available_combos.count > 0
end

#list_itemObject



69
70
71
72
73
74
75
# File 'lib/side.rb', line 69

def list_item
  allergen = allergen_warning || ""

  "#{name.colorize(:blue)} "\
  "#{allergen.strip.colorize(:yellow)}\n  "\
  "#{description.gsub(",", ", ").gsub(")", ") ")}\n".sub("\n  \n", "")
end

#paramsObject



61
62
63
64
65
66
67
# File 'lib/side.rb', line 61

def params
  {
    "shohinC" => id,
    "categoryC" => category_id,
    "setRecommendYosoData" => combo.value
  }
end

#valid?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/side.rb', line 44

def valid?
  url != nil
end