apmex-price 1.1.0 → 1.2.0
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 +29 -29
- data/test/test-apmex-price.rb +41 -37
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fff363ca9069a960361778b6b797a66d2918f3e
|
4
|
+
data.tar.gz: d9f67bc3c30bb2a8fb64ac5c3bb866f017964adb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a23a05a3284c8cbe20d1862297113d0eb87f5492e59a4d4d972fc8c0d4bcedae6093933286ef7b54054fd38e9db25ab27d9ab7098b288c0873516cde4cbfe286
|
7
|
+
data.tar.gz: 8132e9c56f424db67442031c4465bcf8f6a72fd1535571047df6ad9815487640ebd5ec89670e4dd3542ccd9dc4730deb419951972b1b7cad9fb998c2fc026c87
|
data/lib/apmex-price.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'open-uri'
|
3
|
-
|
4
|
-
class ApmexPrice
|
5
|
-
attr_accessor :url, :page, :buy
|
6
|
-
|
7
|
-
DOLLARS_REGEX = /(\d*,*\d+\.\d+)/
|
8
|
-
BUY_CSS = 'div.page-content-main > div > div > strong'
|
9
|
-
|
10
|
-
def initialize(url)
|
11
|
-
@url = url
|
12
|
-
match()
|
13
|
-
end
|
14
|
-
|
15
|
-
def match
|
16
|
-
@page = Nokogiri::HTML(open(@url))
|
17
|
-
@buy = match_dollars(BUY_CSS)
|
18
|
-
end
|
19
|
-
|
20
|
-
def match_dollars(dollars_css)
|
21
|
-
dollars_text = @page.css(dollars_css).text
|
22
|
-
dollars_match = DOLLARS_REGEX.match(dollars_text)
|
23
|
-
|
24
|
-
if dollars_match != nil
|
25
|
-
dollars_match[1].gsub(',', '').to_f
|
26
|
-
else
|
27
|
-
0.0
|
28
|
-
end
|
29
|
-
end
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
class ApmexPrice
|
5
|
+
attr_accessor :url, :page, :buy
|
6
|
+
|
7
|
+
DOLLARS_REGEX = /(\d*,*\d+\.\d+)/
|
8
|
+
BUY_CSS = 'div.page-content-main > div > div > strong'
|
9
|
+
|
10
|
+
def initialize(url)
|
11
|
+
@url = url
|
12
|
+
match()
|
13
|
+
end
|
14
|
+
|
15
|
+
def match
|
16
|
+
@page = Nokogiri::HTML(open(@url))
|
17
|
+
@buy = match_dollars(BUY_CSS)
|
18
|
+
end
|
19
|
+
|
20
|
+
def match_dollars(dollars_css)
|
21
|
+
dollars_text = @page.css(dollars_css).text
|
22
|
+
dollars_match = DOLLARS_REGEX.match(dollars_text)
|
23
|
+
|
24
|
+
if dollars_match != nil
|
25
|
+
dollars_match[1].gsub(',', '').to_f
|
26
|
+
else
|
27
|
+
0.0
|
28
|
+
end
|
29
|
+
end
|
30
30
|
end
|
data/test/test-apmex-price.rb
CHANGED
@@ -1,38 +1,42 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require_relative '../lib/apmex-price'
|
3
|
-
|
4
|
-
class ApmexPriceTest < Minitest::Test
|
5
|
-
def test_
|
6
|
-
apmex_urls = [
|
7
|
-
'http://www.apmex.com/sell-to-us/
|
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/
|
14
|
-
'http://www.apmex.com/sell-to-us/54875',
|
15
|
-
'http://www.apmex.com/sell-to-us/
|
16
|
-
'http://www.apmex.com/sell-to-us/
|
17
|
-
'http://www.apmex.com/sell-to-us/
|
18
|
-
'http://www.apmex.com/sell-to-us/
|
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/
|
23
|
-
'http://www.apmex.com/sell-to-us/
|
24
|
-
'http://www.apmex.com/sell-to-us/
|
25
|
-
'http://www.apmex.com/sell-to-us/
|
26
|
-
'http://www.apmex.com/sell-to-us/
|
27
|
-
'http://www.apmex.com/sell-to-us/
|
28
|
-
'http://www.apmex.com/sell-to-us/
|
29
|
-
'http://www.apmex.com/sell-to-us/
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require_relative '../lib/apmex-price'
|
3
|
+
|
4
|
+
class ApmexPriceTest < Minitest::Test
|
5
|
+
def test_
|
6
|
+
apmex_urls = [
|
7
|
+
'http://www.apmex.com/sell-to-us/3',
|
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/92698',
|
14
|
+
'http://www.apmex.com/sell-to-us/54875',
|
15
|
+
'http://www.apmex.com/sell-to-us/54875',
|
16
|
+
'http://www.apmex.com/sell-to-us/84445',
|
17
|
+
'http://www.apmex.com/sell-to-us/4233',
|
18
|
+
'http://www.apmex.com/sell-to-us/79021',
|
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/93757',
|
23
|
+
'http://www.apmex.com/sell-to-us/72454',
|
24
|
+
'http://www.apmex.com/sell-to-us/72458',
|
25
|
+
'http://www.apmex.com/sell-to-us/79573',
|
26
|
+
'http://www.apmex.com/sell-to-us/69514',
|
27
|
+
'http://www.apmex.com/sell-to-us/87944',
|
28
|
+
'http://www.apmex.com/sell-to-us/11951',
|
29
|
+
'http://www.apmex.com/sell-to-us/57159',
|
30
|
+
'http://www.apmex.com/sell-to-us/92390',
|
31
|
+
'http://www.apmex.com/sell-to-us/43309',
|
32
|
+
'http://www.apmex.com/sell-to-us/72281',
|
33
|
+
'http://www.apmex.com/sell-to-us/72281'
|
34
|
+
]
|
35
|
+
|
36
|
+
apmex_urls.each do |u|
|
37
|
+
a = ApmexPrice.new(u)
|
38
|
+
puts a.buy.to_s
|
39
|
+
assert a.buy.is_a? Float
|
40
|
+
end
|
41
|
+
end
|
38
42
|
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.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cscribn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.8.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.8.1
|
41
41
|
description: Do you own precious metals? Are you interested in getting the current
|
42
42
|
value of your collection? If so, this gem is for you. Simply find the URL of a
|
43
43
|
product you are interested in, pass it as an argument, and you will get back the
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
72
|
rubyforge_project:
|
73
|
-
rubygems_version: 2.
|
73
|
+
rubygems_version: 2.6.11
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: Get buy price of precious metals using apmex.com URLs.
|