class Side

Attributes

allergen_warning[RW]
category_id[RW]
combo[RW]
description[RW]
id[RW]
name[RW]
url[RW]

Public Class Methods

new(element) click to toggle source
# 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

Public Instance Methods

available_combos() click to toggle source
# 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?() click to toggle source
# File lib/side.rb, line 48
def customizable?
  available_combos.count > 0
end
list_item() click to toggle source
# 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
params() click to toggle source
# File lib/side.rb, line 61
def params
  {
    "shohinC" => id,
    "categoryC" => category_id,
    "setRecommendYosoData" => combo.value
  }
end
valid?() click to toggle source
# File lib/side.rb, line 44
def valid?
  url != nil
end

Private Instance Methods

detail_page_content() click to toggle source
# File lib/side.rb, line 79
def detail_page_content
  @detail_page_content ||= Nokogiri::HTML(
    Request.get(url, expect: :ok, failure: "Couldn't open side detail page").body
  )
end