class AmazonDeets::GeneralMerchandiseFragment::Context

Constants

LOG
RatingRegex

Public Instance Methods

current_price() click to toggle source
# File lib/amazon_deets/general_merchandise.rb, line 48
def current_price
  cp_element = agent.page.search("//span[@id='priceblock_saleprice']").first
  if cp_element
    return cp_element.text
  else
    LOG.debug "Looks like no sale is going on.  Returning list price"
    return list_price
  end
end
list_price() click to toggle source
# File lib/amazon_deets/general_merchandise.rb, line 37
def list_price
  lp_element = agent.page.search("//span[@id='priceblock_ourprice']").first
  if lp_element.nil?
    lp_element = agent.page.search("//td[text()='Price:']/following-sibling::td")
  end

  if lp_element
    return lp_element.text.gsub(/[^.\d]/, "")
  end
end
rating() click to toggle source
# File lib/amazon_deets/general_merchandise.rb, line 58
def rating
  result = agent.page.search("//div[@id='averageCustomerReviews']//span[@title]").first
  if result
    m = RatingRegex.match result[:title]
    if m and m[1]
      return m[1]
    end
  end
end
reviews() click to toggle source
# File lib/amazon_deets/general_merchandise.rb, line 68
def reviews
  reviews_element = agent.page.search("//div[@id='averageCustomerReviews']//a[contains(text(), 'reviews')]")
  if reviews_element
    text = reviews_element.text.gsub(/[^\d]/, "")
    return text.to_i unless text.empty?
  else
    LOG.warning "Reviews element could not be found"
  end
end
scrape() click to toggle source
# File lib/amazon_deets/general_merchandise.rb, line 79
def scrape
  return {
    title:         title,
    url:           url,
    list_price:    list_price,
    current_price: current_price,
    rating:        rating,
    reviews:       reviews
  }
end
title() click to toggle source
# File lib/amazon_deets/general_merchandise.rb, line 26
def title
  result = agent.page.search("//h1[@id='title']").first
  if result
    return result.text.strip
  end
end
url() click to toggle source
# File lib/amazon_deets/general_merchandise.rb, line 33
def url
  agent.page.uri.to_s
end