apmex-price 1.0.2 → 1.1.0

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