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.
- checksums.yaml +4 -4
- data/lib/amazon_deets.rb +58 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be524b56abcc6dab4e880b8b27ad49a39ac917b2
|
4
|
+
data.tar.gz: 60047f9e529b38ad24d11e2562cb2bf5ba1ee590
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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("//
|
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
|
-
|
29
|
-
if
|
30
|
-
|
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
|
-
|
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='
|
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 =
|
44
|
-
|
45
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
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
|
|