amazon_deets 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/amazon_deets.rb +58 -13
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6346c63b7df93193f217123d641590ebb734234
4
- data.tar.gz: e1677c1d3a21f891eb14ae3f854fe578efe83e1b
3
+ metadata.gz: be524b56abcc6dab4e880b8b27ad49a39ac917b2
4
+ data.tar.gz: 60047f9e529b38ad24d11e2562cb2bf5ba1ee590
5
5
  SHA512:
6
- metadata.gz: 4757b812c3f36dc4193c8a445b4f4068fb4f80f8455d03f66b7fc02579356a248e1804b846169ceef0d12314b718ed8d389b1015c6dd659e3b7d5c4813b14403
7
- data.tar.gz: 1727f43e5edbf5b6c1c390fef16c5b99ba22d26544cea023ae3e52aab899da1ca55cfd71450017ba95bb24a3cb649ff95648c3cd1f6885ccec14471b7bccedea
6
+ metadata.gz: e9cedb5fa453d9f082a403998154297bd1b1fd7af47cb23f53f4929ad849af96b92572b307e3f0e4fe3da4314cfb21f0b723c9834b351ee77f5fce08337f1eb7
7
+ data.tar.gz: fb0a0f570667b9c583e1e22240d3738e7397c97ca1304ecc4de80169f00db5564a818d0faa2fed3031190810d3dcfcdbb61ce025adaa45af9292b372fe91aad4
data/lib/amazon_deets.rb CHANGED
@@ -16,39 +16,84 @@ module AmazonDeets
16
16
  end
17
17
 
18
18
  def title
19
- agent.page.search("//span[@id='btAsinTitle']").text
19
+ result = agent.page.search("//h1[@id='title']").first
20
+ if result
21
+ return result.text.strip
22
+ end
23
+
24
+ result = agent.page.search("span#btAsinTitle").first
25
+ if result
26
+ return result.text.strip
27
+ end
28
+
29
+ return nil
20
30
  end
21
31
 
32
+
22
33
  def url
23
34
  agent.page.uri.to_s
24
35
  end
25
36
 
26
37
 
27
38
  def list_price
28
- nodes = agent.page.search("//span[@id='listPriceValue']")
29
- if nodes.any?
30
- return nodes.text
39
+ lp_element = agent.page.search("//span[@id='priceblock_ourprice']").first
40
+ if lp_element.nil?
41
+ lp_element = agent.page.search("//td[text()='Price:']/following-sibling::td")
42
+ end
43
+
44
+ if lp_element
45
+ return lp_element.text.gsub(/[^.\d]/, "")
31
46
  else
32
- LOG.debug "List price was not found. Returning current price instead."
33
- return current_price
47
+ return nil
34
48
  end
49
+
35
50
  end
36
51
 
37
52
  def current_price
38
- agent.page.search("//span[@id='actualPriceValue']").text
53
+ current_price_element = agent.page.search("//span[@id='priceblock_saleprice']").first
54
+ if current_price_element
55
+ return current_price_element.text
56
+ else
57
+ LOG.debug "Looks like no sale is going on. Returning list price"
58
+ return list_price
59
+ end
39
60
  end
40
61
 
41
62
 
63
+ def rating_text
64
+ result = agent.page.search("//div[@id='averageCustomerReviews']//span[@title]").first
65
+ if result
66
+ return result[:title]
67
+ end
68
+
69
+ result = agent.page.search("div.acrRating").first
70
+ if result
71
+ return result.text
72
+ end
73
+
74
+ return nil
75
+ end
76
+
42
77
  def rating
43
- text = agent.page.search("//div[@id='acr']//span[@title]").text
44
- m = RatingRegex.match(text)
45
- m[1].to_f
78
+ text = rating_text
79
+ if text
80
+ m = RatingRegex.match(text)
81
+ if m and m[1]
82
+ return m[1].to_f
83
+ end
84
+ end
85
+
86
+ return nil
46
87
  end
47
88
 
48
89
  def reviews
49
- text = agent.page.search("//div[@id='acr']//div[contains(@class, 'acrCount')]").text
50
- m = ReviewsRegex.match(text)
51
- m[1].to_i
90
+ reviews_element = agent.page.search("//div[@id='summaryStars']/a")
91
+ if reviews_element
92
+ text = reviews_element.text.gsub(/[^\d]/, "")
93
+
94
+ return text.to_i unless text.empty?
95
+ end
96
+ return nil
52
97
  end
53
98
 
54
99
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amazon_deets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Lauber