class AmazonDeets::KindleFragment::Context

Constants

LOG
RatingRegex

Public Instance Methods

current_price() click to toggle source
# File lib/amazon_deets/kindle.rb, line 44
def current_price
  cp_element = agent.page.search("td b.priceLarge").first
  if cp_element
    return cp_element.text.gsub(/[^.\d]/, "")
  end
end
list_price() click to toggle source
# File lib/amazon_deets/kindle.rb, line 37
def list_price
  lp_element = agent.page.search("td.listPrice").first
  if lp_element
    return lp_element.text.gsub(/[^.\d]/, "")
  end
end
rating() click to toggle source
# File lib/amazon_deets/kindle.rb, line 51
def rating
  result = agent.page.search("span.crAvgStars span[title$='5 stars']").first
  if result
    m = RatingRegex.match result[:title]
    LOG.info result[:title]
    if m and m[1]
      return m[1]
    end
  else
    LOG.warning "Unable to locate rating element"
  end
end
reviews() click to toggle source
# File lib/amazon_deets/kindle.rb, line 64
def reviews
  reviews_element = agent.page.search("//span[@class='crAvgStars']/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/kindle.rb, line 74
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/kindle.rb, line 26
def title
  result = agent.page.search("span#btAsinTitle").first
  if result
    return result.text.strip
  end
end
url() click to toggle source
# File lib/amazon_deets/kindle.rb, line 33
def url
  agent.page.uri.to_s
end