apmex-price 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apmex-price.rb +13 -6
- data/test/test-apmex-price.rb +4 -41
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d7e2d02bdfdc85d869a95c8325a22f58ed3ea14
|
4
|
+
data.tar.gz: 650756852828709f53dc58e59644fe5e4cfb28bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5855096f37cc28464f3bd2abb64a2cbe52d9e9d2c3ff63fab130fc15a41309ca72c6011b79c94c4da8a86cc43dda7ec548a5f76be8e10726aba3cc5882e8f3d3
|
7
|
+
data.tar.gz: 4d8ccde92e3c868396edc3215d009fd198106235468d10d56cbe2a7df67f70f9eaa86a5a48f15341ca72cb299fde2be130ae9bcaad64c7937e7476682adc4b8f
|
data/lib/apmex-price.rb
CHANGED
@@ -3,11 +3,13 @@ require 'nokogiri'
|
|
3
3
|
require 'open-uri'
|
4
4
|
|
5
5
|
class ApmexPrice
|
6
|
-
attr_accessor :url, :page, :spot, :ounces_spot, :buy, :sell, :
|
6
|
+
attr_accessor :url, :page, :spot, :ounces_spot, :buy, :sell, :value
|
7
7
|
|
8
8
|
DOLLARS_REGEX = /(\d*,*\d+\.\d+)/
|
9
9
|
OUNCES_REGEX = /(\d*,*\d+\.?\d*)/
|
10
|
+
OUNCES_LABEL_CSS = 'div.product-specs > table > tbody > tr:nth-child(7) > th'
|
10
11
|
OUNCES_CSS = 'div.product-specs > table > tbody > tr:nth-child(7) > td'
|
12
|
+
OUNCES2_CSS = 'div.product-specs > table > tbody > tr:nth-child(6) > td'
|
11
13
|
SPOT_CSS = 'span.item-bid'
|
12
14
|
BUY_CSS = 'div.product-buy-price > h4 > a'
|
13
15
|
SELL_CSS = 'table.table-volume-pricing > tbody > tr:nth-child(1) > td:nth-child(2)'
|
@@ -21,8 +23,13 @@ class ApmexPrice
|
|
21
23
|
def match
|
22
24
|
@page = Nokogiri::HTML(open(@url))
|
23
25
|
|
24
|
-
# Get ounces
|
25
|
-
|
26
|
+
# Get ounces. They are usually the 7th child, but there is at least one case for which they are the 6th.
|
27
|
+
if @page.css(OUNCES_LABEL_CSS).text == 'Metal Content:'
|
28
|
+
ounces_text = @page.css(OUNCES_CSS).text
|
29
|
+
else
|
30
|
+
ounces_text = @page.css(OUNCES2_CSS).text
|
31
|
+
end
|
32
|
+
|
26
33
|
ounces_match = OUNCES_REGEX.match(ounces_text)
|
27
34
|
@ounces = ounces_match[0].to_f
|
28
35
|
|
@@ -36,9 +43,9 @@ class ApmexPrice
|
|
36
43
|
@ounces_spot = @spot * @ounces
|
37
44
|
|
38
45
|
if @buy != 0.0
|
39
|
-
@
|
46
|
+
@value = @buy
|
40
47
|
else
|
41
|
-
@
|
48
|
+
@value = @ounces_spot
|
42
49
|
end
|
43
50
|
end
|
44
51
|
|
@@ -55,6 +62,6 @@ class ApmexPrice
|
|
55
62
|
|
56
63
|
# Aid in creating CSV files
|
57
64
|
def to_s
|
58
|
-
@
|
65
|
+
@value.to_s + ',' + @ounces_spot.to_s + ',' + @buy.to_s + ',' + @sell.to_s
|
59
66
|
end
|
60
67
|
end
|
data/test/test-apmex-price.rb
CHANGED
@@ -4,75 +4,38 @@ require 'apmex-price'
|
|
4
4
|
class ApmexPriceTest < Minitest::Unit::TestCase
|
5
5
|
def test
|
6
6
|
apmex_urls = [
|
7
|
-
'http://www.apmex.com/product/3/1-4-oz-gold-american-eagle-random-year',
|
8
|
-
'http://www.apmex.com/product/3/1-4-oz-gold-american-eagle-random-year',
|
9
7
|
'http://www.apmex.com/product/3/1-4-oz-gold-american-eagle-random-year',
|
10
8
|
'http://www.apmex.com/product/1/1-oz-gold-american-eagle-random-year',
|
11
9
|
'http://www.apmex.com/product/23331/1-oz-silver-american-eagle-random-year',
|
12
10
|
'http://www.apmex.com/product/23331/1-oz-silver-american-eagle-random-year',
|
13
11
|
'http://www.apmex.com/product/23331/1-oz-silver-american-eagle-random-year',
|
14
|
-
'http://www.apmex.com/product/23331/1-oz-silver-american-eagle-random-year',
|
15
|
-
'http://www.apmex.com/product/79019/2014-1-oz-silver-american-eagle-bu',
|
16
|
-
'http://www.apmex.com/product/79019/2014-1-oz-silver-american-eagle-bu',
|
17
12
|
'http://www.apmex.com/product/79019/2014-1-oz-silver-american-eagle-bu',
|
18
|
-
'http://www.apmex.com/product/79019/2014-1-oz-silver-american-eagle-bu',
|
19
|
-
'http://www.apmex.com/product/79019/2014-1-oz-silver-american-eagle-bu',
|
20
|
-
'http://www.apmex.com/product/79019/2014-1-oz-silver-american-eagle-bu',
|
21
|
-
'http://www.apmex.com/product/79019/2014-1-oz-silver-american-eagle-bu',
|
22
|
-
'http://www.apmex.com/product/54875/2010-australia-1-oz-silver-kookaburra-bu',
|
23
13
|
'http://www.apmex.com/product/54875/2010-australia-1-oz-silver-kookaburra-bu',
|
24
14
|
'http://www.apmex.com/product/54875/2010-australia-1-oz-silver-kookaburra-bu',
|
25
15
|
'http://www.apmex.com/product/84445/2015-australia-1-oz-silver-kookaburra-bu',
|
26
|
-
'http://www.apmex.com/product/84445/2015-australia-1-oz-silver-kookaburra-bu',
|
27
|
-
'http://www.apmex.com/product/84445/2015-australia-1-oz-silver-kookaburra-bu',
|
28
|
-
'http://www.apmex.com/product/84445/2015-australia-1-oz-silver-kookaburra-bu',
|
29
|
-
'http://www.apmex.com/product/84445/2015-australia-1-oz-silver-kookaburra-bu',
|
30
|
-
'http://www.apmex.com/product/84445/2015-australia-1-oz-silver-kookaburra-bu',
|
31
|
-
'http://www.apmex.com/product/84445/2015-australia-1-oz-silver-kookaburra-bu',
|
32
16
|
'http://www.apmex.com/product/79047/2014-1-10-oz-gold-austrian-philharmonic',
|
33
17
|
'http://www.apmex.com/product/79021/2014-austria-1-oz-silver-philharmonic',
|
34
|
-
'http://www.apmex.com/product/79021/2014-austria-1-oz-silver-philharmonic',
|
35
|
-
'http://www.apmex.com/product/79021/2014-austria-1-oz-silver-philharmonic',
|
36
|
-
'http://www.apmex.com/product/79021/2014-austria-1-oz-silver-philharmonic',
|
37
|
-
'http://www.apmex.com/product/79021/2014-austria-1-oz-silver-philharmonic',
|
38
|
-
'http://www.apmex.com/product/79021/2014-austria-1-oz-silver-philharmonic',
|
39
|
-
'http://www.apmex.com/product/79021/2014-austria-1-oz-silver-philharmonic',
|
40
|
-
'http://www.apmex.com/product/79021/2014-austria-1-oz-silver-philharmonic',
|
41
|
-
'http://www.apmex.com/product/79021/2014-austria-1-oz-silver-philharmonic',
|
42
|
-
'http://www.apmex.com/product/79021/2014-austria-1-oz-silver-philharmonic',
|
43
18
|
'http://www.apmex.com/product/79573/2014-1-oz-silver-britannia-brilliant-uncirculated',
|
44
19
|
'http://www.apmex.com/product/12/1-10-oz-gold-canadian-maple-leaf-random-year',
|
45
20
|
'http://www.apmex.com/product/79041/2014-canada-1-4-oz-gold-maple-leaf-bu',
|
46
|
-
'http://www.apmex.com/product/79041/2014-canada-1-4-oz-gold-maple-leaf-bu',
|
47
|
-
'http://www.apmex.com/product/79041/2014-canada-1-4-oz-gold-maple-leaf-bu',
|
48
21
|
'http://www.apmex.com/product/1090/1-oz-silver-canadian-maple-leaf-random-year',
|
49
|
-
'http://www.apmex.com/product/
|
50
|
-
'http://www.apmex.com/product/72458/2013-china-1-oz-silver-panda-bu-in-capsule',
|
22
|
+
'http://www.apmex.com/product/72454/2013-china-1-10-oz-gold-panda-bu-sealed',
|
51
23
|
'http://www.apmex.com/product/72458/2013-china-1-oz-silver-panda-bu-in-capsule',
|
52
24
|
'http://www.apmex.com/product/1114/1-oz-silver-mexican-libertad-random-year',
|
53
|
-
'http://www.apmex.com/product/1114/1-oz-silver-mexican-libertad-random-year',
|
54
|
-
'http://www.apmex.com/product/1114/1-oz-silver-mexican-libertad-random-year',
|
55
|
-
'http://www.apmex.com/product/1114/1-oz-silver-mexican-libertad-random-year',
|
56
25
|
'http://www.apmex.com/product/11951/1-oz-pamp-suisse-gold-bar-9999-fine-in-assay',
|
57
26
|
'http://www.apmex.com/product/57159/1-oz-perth-mint-gold-bar-9999-fine-in-assay',
|
58
27
|
'http://www.apmex.com/product/21/10-oz-silver-bar-secondary-market-999-fine',
|
59
|
-
'http://www.apmex.com/product/21/10-oz-silver-bar-secondary-market-999-fine',
|
60
|
-
'http://www.apmex.com/product/21/10-oz-silver-bar-secondary-market-999-fine',
|
61
|
-
'http://www.apmex.com/product/21/10-oz-silver-bar-secondary-market-999-fine',
|
62
|
-
'http://www.apmex.com/product/72281/10-oz-sunshine-silver-bar-999-fine-v2',
|
63
|
-
'http://www.apmex.com/product/72281/10-oz-sunshine-silver-bar-999-fine-v2',
|
64
|
-
'http://www.apmex.com/product/72281/10-oz-sunshine-silver-bar-999-fine-v2',
|
65
28
|
'http://www.apmex.com/product/72281/10-oz-sunshine-silver-bar-999-fine-v2',
|
66
29
|
'http://www.apmex.com/product/72281/10-oz-sunshine-silver-bar-999-fine-v2'
|
67
30
|
]
|
68
31
|
|
69
|
-
puts '
|
32
|
+
puts 'Value,Spot,Buy,Sell'
|
70
33
|
|
71
34
|
apmex_urls.each do |u|
|
72
35
|
a = ApmexPrice.new(u)
|
73
36
|
puts a.to_s
|
74
|
-
assert a.
|
75
|
-
assert a.
|
37
|
+
assert a.value.is_a? Float
|
38
|
+
assert a.ounces_spot.is_a? Float
|
76
39
|
assert a.buy.is_a? Float
|
77
40
|
assert a.sell.is_a? Float
|
78
41
|
end
|
metadata
CHANGED
@@ -1,22 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apmex-price
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cscribn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Do you own precious metals? Are you interested in getting the current
|
14
14
|
value of your collection? If so, this gem is for you. Simply find the URL of a product
|
15
15
|
you are interested in, pass it as an argument, and you will get back the spot, buy,
|
16
|
-
sell, and
|
17
|
-
|
18
|
-
|
19
|
-
design changes.
|
16
|
+
sell, and value price. The value is either the APMEX buy price or the spot price
|
17
|
+
if the buy price is not available. This program relies on CSS paths of the apmex.com
|
18
|
+
website, and will therefore need to be updated whenever the site design changes.
|
20
19
|
email:
|
21
20
|
executables: []
|
22
21
|
extensions: []
|
@@ -47,6 +46,6 @@ rubyforge_project:
|
|
47
46
|
rubygems_version: 2.0.15
|
48
47
|
signing_key:
|
49
48
|
specification_version: 4
|
50
|
-
summary: Get spot, buy, sell, and
|
49
|
+
summary: Get spot, buy, sell, and value prices of precious metals using apmex.com
|
51
50
|
URLs.
|
52
51
|
test_files: []
|