class WeddingRegistryScraper::Registries::CrateAndBarrel

Private Instance Methods

get_desired(product) click to toggle source
# File lib/wedding_registry_scraper/registries/crate_and_barrel.rb, line 34
def get_desired(product)
  product.css('td')[4].css('.itemHas').text.strip.to_i
end
get_image_url(product) click to toggle source
# File lib/wedding_registry_scraper/registries/crate_and_barrel.rb, line 23
def get_image_url(product)
  thumb_src = product.css('img')[0]['src']
  thumb_src.sub(/\$web_itembasket\$/, '&$web_popup_zoom$&wid=379&hei=379')
end
get_name(product) click to toggle source
# File lib/wedding_registry_scraper/registries/crate_and_barrel.rb, line 9
def get_name(product)
  product.css('.itemTitle').text.strip
end
get_price(product) click to toggle source
# File lib/wedding_registry_scraper/registries/crate_and_barrel.rb, line 38
def get_price(product)
  if (sale_price = product.css('.salePrice')).any?
    /\$?(\d+(\.\d+)?)/.match(sale_price.text) { |match| match[1].to_f }
  elsif (regular_price = product.css('.regPrice')).any?
    /\$?(\d+(\.\d+)?)/.match(regular_price.text) { |match| match[1].to_f }
  end
end
get_products(doc) click to toggle source
# File lib/wedding_registry_scraper/registries/crate_and_barrel.rb, line 5
def get_products(doc)
  doc.css('.jsItemRow:not(.emptyCategoryRow)')
end
get_remaining(product) click to toggle source
# File lib/wedding_registry_scraper/registries/crate_and_barrel.rb, line 28
def get_remaining(product)
  desired = product.css('td')[4].css('.itemHas').text.strip.to_i
  fulfilled = product.css('td')[5].css('.itemHas').text.strip.to_i
  desired - fulfilled
end
get_sku(product) click to toggle source
# File lib/wedding_registry_scraper/registries/crate_and_barrel.rb, line 13
def get_sku(product)
  sku = product.css('.skuNum').text.strip.match(/SKU (\S+)/)[1]
  "c&b:#{sku}"
end
get_url(product) click to toggle source
# File lib/wedding_registry_scraper/registries/crate_and_barrel.rb, line 18
def get_url(product)
  # TODO pop up modal? set proper anchor (they're not unique!)
  @url
end