Class: PriceGrabberSource

Inherits:
Source
  • Object
show all
Defined in:
lib/sources/price_grabber_source.rb

Constant Summary

Constants inherited from Source

Source::SIMPLE_SOURCES_YAML_FILE

Instance Attribute Summary

Attributes inherited from Source

#batch_fetch_delay, #cpc, #for_product_info, #for_review_aggregates, #homepage, #mappable, #name, #offer_affiliate, #offer_enabled, #offer_ttl_seconds, #product_code_examples, #product_code_regexp, #product_page_link_erb, #search_token_separator, #search_url, #supports_lifetime_ratings, #use_for_merchant_ratings

Instance Method Summary collapse

Methods inherited from Source

affiliate_sources, #eql?, #fetch_offers, #hash, inherited, #keyname, keyname, keyname=, merchant_rating_sources, method_missing, #nullify_offer_url, offer_sources, #product_code_valid?, #product_page_link, source, sources, #to_s, #url_for_merchant_source_page_alt

Constructor Details

#initializePriceGrabberSource

Returns a new instance of PriceGrabberSource.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sources/price_grabber_source.rb', line 4

def initialize
  super(:name => 'PriceGrabber',
        :homepage => ' http://www.pricegrabber.com/',
        :cpc => 0,
        :offer_enabled => false,
        :offer_ttl_seconds => 0,
        :use_for_merchant_ratings => true,
        :offer_affiliate => false,
        :supports_lifetime_ratings => false,
        :batch_fetch_delay => 2,
        :product_code_regexp => /^\d{6,9}$/,
        :product_code_examples => ['716698181', '563043'],
        :product_page_link_erb => "http://reviews.pricegrabber.com/-/m/<%= product_code %>/")
end

Instance Method Details

#code_from_merchant_source_page_url(merchant_source_page_url) ⇒ Object



23
24
25
# File 'lib/sources/price_grabber_source.rb', line 23

def code_from_merchant_source_page_url(merchant_source_page_url)
  merchant_source_page_url.match(/pricegrabber\.com.*\/r[\/=](\d+)/)[1]
end

#fetch_merchant_source(merchant_source_page_url) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/sources/price_grabber_source.rb', line 27

def fetch_merchant_source(merchant_source_page_url)
  delay_fetch
  doc = Hpricot(open(merchant_source_page_url))

  merchant_source = OpenStruct.new
  merchant_source.source = self

  merchant_identity_block = doc.at('div#merchantIdentityBlock')

  unless merchant_identity_block.nil?
    # merchant name
    element = merchant_identity_block.at('/h4')
    unless element.nil?
      name = element.inner_text.strip
      merchant_source.name = name
    end

    # merchant logo
    element = merchant_identity_block.at('/img')
    unless element.nil?
      logo_url = element.attributes['src']
      merchant_source.logo_url = logo_url
    end
  end

  # merchant code
  merchant_source.code = code_from_merchant_source_page_url(merchant_source_page_url)

  # merchant rating
  ratings = doc.search('table#scoreTable/tr/th[text() = "Avg Rating"]/../td')
  unless ratings.nil?
    unless ratings[0].nil?
      three_month_rating = ratings[0].inner_text.strip.to_f
      merchant_source.merchant_rating = (three_month_rating * 20).round
    end

    unless ratings[2].nil?
      lifetime_month_rating = ratings[2].inner_text.strip.to_f
      merchant_source.merchant_rating_lifetime = (lifetime_month_rating * 20).round
    end
  end

  # Num Merchant Reviews
  num_reviews = doc.search('table#scoreTable/tr/th[text() = "Total Reviews"]/../td')
  unless num_reviews.nil?
    unless num_reviews[0].nil?
      merchant_source.num_merchant_reviews = num_reviews[0].inner_text.strip.to_i
    end

    unless num_reviews[2].nil?
      merchant_source.num_merchant_reviews_lifetime = num_reviews[2].inner_text.strip.to_i
    end
  end

  # Homepage
  element = doc.at('table#contactTable//th[text() = "Website:"]/../td/a')
  unless element.nil?
    homepage = element.inner_text.strip.downcase
    merchant_source.homepage = homepage
  end

  merchant_source
end

#format_rating(merchant_source) ⇒ Object



91
92
93
# File 'lib/sources/price_grabber_source.rb', line 91

def format_rating(merchant_source)
  '%01.2f/5.0' % (merchant_source.get_merchant_rating.to_f / 20.0)
end

#url_for_merchant_source_page(merchant_source_code) ⇒ Object



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

def url_for_merchant_source_page(merchant_source_code)
  "http://www.pricegrabber.com/info_retailer.php/r=#{merchant_source_code}"
end