currency_spy 0.0.1 → 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.
- data/Gemfile.lock +8 -1
- data/README.rdoc +8 -0
- data/currency_spy.gemspec +1 -0
- data/doc/CurrencySpy.html +277 -0
- data/doc/CurrencySpy/DnbNord.html +454 -0
- data/doc/CurrencySpy/Nbp.html +377 -0
- data/doc/CurrencySpy/Scraper.html +461 -0
- data/doc/CurrencySpy/Walutomat.html +331 -0
- data/doc/Gemfile.html +106 -0
- data/doc/LICENSE.html +125 -0
- data/doc/README_rdoc.html +149 -0
- data/doc/Rakefile.html +103 -0
- data/doc/created.rid +17 -0
- data/doc/index.html +106 -0
- data/doc/lib/currency_spy/dnb_nord_rb.html +52 -0
- data/doc/lib/currency_spy/nbp_rb.html +52 -0
- data/doc/lib/currency_spy/scraper_rb.html +52 -0
- data/doc/lib/currency_spy/version_rb.html +52 -0
- data/doc/lib/currency_spy/walutomat_rb.html +52 -0
- data/doc/lib/currency_spy_rb.html +56 -0
- data/doc/rdoc.css +706 -0
- data/doc/spec/dnb_nord_spec_rb.html +54 -0
- data/doc/spec/nbp_spec_rb.html +54 -0
- data/doc/spec/scraper_spec_rb.html +54 -0
- data/doc/spec/spec_helper_rb.html +56 -0
- data/doc/spec/walutomat_spec_rb.html +54 -0
- data/lib/currency_spy.rb +17 -1
- data/lib/currency_spy/dnb_nord.rb +57 -0
- data/lib/currency_spy/nbp.rb +17 -9
- data/lib/currency_spy/scraper.rb +52 -23
- data/lib/currency_spy/version.rb +2 -1
- data/lib/currency_spy/walutomat.rb +43 -0
- data/spec/dnb_nord_spec.rb +47 -0
- data/spec/nbp_spec.rb +8 -0
- data/spec/scraper_spec.rb +26 -16
- data/spec/walutomat_spec.rb +33 -0
- metadata +45 -3
data/lib/currency_spy/version.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
module CurrencySpy
|
2
|
+
# A class designed to fetch medium currency rates from Walutomat.pl a social currency exchange platform.
|
3
|
+
class Walutomat < CurrencySpy::Scraper
|
4
|
+
|
5
|
+
# Constructor method.
|
6
|
+
# Initializes the following:
|
7
|
+
# * a url of the source
|
8
|
+
# * and the name of the source
|
9
|
+
# * a list of currency codes available
|
10
|
+
def initialize
|
11
|
+
super
|
12
|
+
@url = 'http://www.walutomat.pl/rates.php'
|
13
|
+
@institution = 'Walutomat'
|
14
|
+
@available_codes = %w(EUR USD GBP CHF)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Fetch medium rate which is calculated based on current transactions in Walutomat
|
18
|
+
def medium_rate
|
19
|
+
regexp = Regexp.new("#{currency_code} / PLN")
|
20
|
+
res = nil
|
21
|
+
page.search("//td[@name='pair']").each do |td|
|
22
|
+
if (regexp.match(td.content))
|
23
|
+
res = td.next_element.content.to_f
|
24
|
+
end
|
25
|
+
end
|
26
|
+
return res
|
27
|
+
end
|
28
|
+
|
29
|
+
# The hour of the rate
|
30
|
+
def rate_time
|
31
|
+
regexp = Regexp.new(currency_code)
|
32
|
+
time_regexp = Regexp.new(/\d+:\d+/)
|
33
|
+
res = nil
|
34
|
+
page.search("//td[@name='pair']").each do |td|
|
35
|
+
if (regexp.match(td.content))
|
36
|
+
hour = td.next_element.next_element.content
|
37
|
+
res = DateTime.parse(hour)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
return res
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "A DnbNord scraper instance" do
|
4
|
+
before :each do
|
5
|
+
@scraper = CurrencySpy::DnbNord.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return the name of the institution" do
|
9
|
+
@scraper.institution.should == "DnB Nord"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have a proper url defined" do
|
13
|
+
@scraper.session_no = 1
|
14
|
+
@scraper.url.should == 'http://www.dnbnord.pl/pl/tabela-kursow-walut-dla-kredytow/go:godzina=08:15'
|
15
|
+
@scraper.session_no = 2
|
16
|
+
@scraper.url.should == 'http://www.dnbnord.pl/pl/tabela-kursow-walut-dla-kredytow/go:godzina=12:15'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should contain a list of available currency codes" do
|
20
|
+
@scraper.available_codes.should_not be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return currency values" do
|
24
|
+
@scraper.session_no = 1
|
25
|
+
@scraper.fetch_rates.should_not be_nil
|
26
|
+
@scraper.fetch_rates.length.should == 3
|
27
|
+
@scraper.buy_rate.should == @scraper.fetch_rates[:buy_rate]
|
28
|
+
@scraper.sell_rate.should == @scraper.fetch_rates[:sell_rate]
|
29
|
+
@scraper.rate_time.should == @scraper.fetch_rates[:rate_time]
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return a buy rate smaller than the sell rate" do
|
33
|
+
@scraper.buy_rate.should < @scraper.sell_rate
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return buy rate as a float" do
|
37
|
+
@scraper.fetch_rates[:buy_rate].should be_a_kind_of(Float)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return sell rate as a float" do
|
41
|
+
@scraper.fetch_rates[:sell_rate].should be_a_kind_of(Float)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return rate time as a DateTime instance" do
|
45
|
+
@scraper.fetch_rates[:rate_time].should be_a_kind_of(DateTime)
|
46
|
+
end
|
47
|
+
end
|
data/spec/nbp_spec.rb
CHANGED
@@ -5,10 +5,18 @@ describe "A Nbp scraper instance" do
|
|
5
5
|
@scraper = CurrencySpy::Nbp.new
|
6
6
|
end
|
7
7
|
|
8
|
+
it "should return the name of the institution" do
|
9
|
+
@scraper.institution.should == "Narodowy Bank Polski"
|
10
|
+
end
|
11
|
+
|
8
12
|
it "should have a proper url defined" do
|
9
13
|
@scraper.url.should == 'http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html'
|
10
14
|
end
|
11
15
|
|
16
|
+
it "should contain a list of available currency codes" do
|
17
|
+
@scraper.available_codes.should_not be_nil
|
18
|
+
end
|
19
|
+
|
12
20
|
it "should return currency values" do
|
13
21
|
@scraper.fetch_rates.should_not be_nil
|
14
22
|
@scraper.fetch_rates.length.should == 3
|
data/spec/scraper_spec.rb
CHANGED
@@ -1,32 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "A
|
4
|
-
it "Should have a list of available currency codes" do
|
5
|
-
CurrencySpy::Scraper::AVAILABLE_CODES.should_not be_empty
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "An instance of scraper" do
|
3
|
+
describe "A plain instance of scraper" do
|
10
4
|
before :each do
|
11
5
|
@scraper = CurrencySpy::Scraper.new
|
12
6
|
end
|
13
7
|
|
14
|
-
it "should
|
15
|
-
|
8
|
+
it "should not contain a list of available currency codes" do
|
9
|
+
@scraper.available_codes.should be_nil
|
16
10
|
end
|
17
11
|
|
18
|
-
it "should raise an exception if
|
19
|
-
|
20
|
-
lambda {@scraper.
|
21
|
-
lambda {@scraper.rate_time}.should raise_error(NotImplementedError)
|
12
|
+
it "should raise an exception if fetch_rate is called on Scraper class instance" do
|
13
|
+
@scraper.currency_code = "XYZ"
|
14
|
+
lambda {@scraper.fetch_rates}.should raise_error(Exception, "This method should be invoked from CurrencySpy::Scraper sub class")
|
22
15
|
end
|
23
16
|
|
24
|
-
it "should
|
25
|
-
@scraper.
|
26
|
-
@scraper.parser.should be_a_kind_of Mechanize
|
17
|
+
it "should not parse any pages" do
|
18
|
+
@scraper.page.should be_nil
|
27
19
|
end
|
28
20
|
|
29
21
|
it "should assign default properties" do
|
30
22
|
@scraper.url.should be_nil
|
31
23
|
end
|
32
24
|
end
|
25
|
+
|
26
|
+
describe "An instance of a scraper with an URI" do
|
27
|
+
before :each do
|
28
|
+
@scraper = CurrencySpy::Scraper.new
|
29
|
+
@scraper.url = 'http://www.google.com'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return a Mechanize::Page instance on a call to page" do
|
33
|
+
@scraper.page.should_not be_nil
|
34
|
+
@scraper.page.should be_a_kind_of Mechanize::Page
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should reload the page object if necessary" do
|
38
|
+
cached = @scraper.page
|
39
|
+
@scraper.page.should equal cached
|
40
|
+
@scraper.page(reload = true).should_not equal cached
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "A Walutomat scraper instance" do
|
4
|
+
before :each do
|
5
|
+
@scraper = CurrencySpy::Walutomat.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return the name of the institution" do
|
9
|
+
@scraper.institution.should == "Walutomat"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have a proper url defined" do
|
13
|
+
@scraper.url.should == 'http://www.walutomat.pl/rates.php'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should contain a list of available currency codes" do
|
17
|
+
@scraper.available_codes.should_not be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return currency values" do
|
21
|
+
@scraper.fetch_rates.should_not be_nil
|
22
|
+
@scraper.fetch_rates.length.should == 2
|
23
|
+
@scraper.medium_rate.should == @scraper.fetch_rates[:medium_rate]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return a medium rate as a float" do
|
27
|
+
@scraper.fetch_rates[:medium_rate].should be_a_kind_of(Float)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return rate time as a DateTime instance" do
|
31
|
+
@scraper.fetch_rates[:rate_time].should be_a_kind_of(DateTime)
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Lukasz Badura
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-12 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -43,6 +43,19 @@ dependencies:
|
|
43
43
|
version: "0"
|
44
44
|
type: :runtime
|
45
45
|
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
type: :runtime
|
58
|
+
version_requirements: *id003
|
46
59
|
description: A simple gem to parse and fetch currency rates from different websites.
|
47
60
|
email:
|
48
61
|
- lukasz@niebo.net
|
@@ -60,13 +73,40 @@ files:
|
|
60
73
|
- README.rdoc
|
61
74
|
- Rakefile
|
62
75
|
- currency_spy.gemspec
|
76
|
+
- doc/CurrencySpy.html
|
77
|
+
- doc/CurrencySpy/DnbNord.html
|
78
|
+
- doc/CurrencySpy/Nbp.html
|
79
|
+
- doc/CurrencySpy/Scraper.html
|
80
|
+
- doc/CurrencySpy/Walutomat.html
|
81
|
+
- doc/Gemfile.html
|
82
|
+
- doc/LICENSE.html
|
83
|
+
- doc/README_rdoc.html
|
84
|
+
- doc/Rakefile.html
|
85
|
+
- doc/created.rid
|
86
|
+
- doc/index.html
|
87
|
+
- doc/lib/currency_spy/dnb_nord_rb.html
|
88
|
+
- doc/lib/currency_spy/nbp_rb.html
|
89
|
+
- doc/lib/currency_spy/scraper_rb.html
|
90
|
+
- doc/lib/currency_spy/version_rb.html
|
91
|
+
- doc/lib/currency_spy/walutomat_rb.html
|
92
|
+
- doc/lib/currency_spy_rb.html
|
93
|
+
- doc/rdoc.css
|
94
|
+
- doc/spec/dnb_nord_spec_rb.html
|
95
|
+
- doc/spec/nbp_spec_rb.html
|
96
|
+
- doc/spec/scraper_spec_rb.html
|
97
|
+
- doc/spec/spec_helper_rb.html
|
98
|
+
- doc/spec/walutomat_spec_rb.html
|
63
99
|
- lib/currency_spy.rb
|
100
|
+
- lib/currency_spy/dnb_nord.rb
|
64
101
|
- lib/currency_spy/nbp.rb
|
65
102
|
- lib/currency_spy/scraper.rb
|
66
103
|
- lib/currency_spy/version.rb
|
104
|
+
- lib/currency_spy/walutomat.rb
|
105
|
+
- spec/dnb_nord_spec.rb
|
67
106
|
- spec/nbp_spec.rb
|
68
107
|
- spec/scraper_spec.rb
|
69
108
|
- spec/spec_helper.rb
|
109
|
+
- spec/walutomat_spec.rb
|
70
110
|
has_rdoc: true
|
71
111
|
homepage: http://rubygems.org/gems/currency_spy
|
72
112
|
licenses: []
|
@@ -100,6 +140,8 @@ signing_key:
|
|
100
140
|
specification_version: 3
|
101
141
|
summary: A gem to fetch currency rates.
|
102
142
|
test_files:
|
143
|
+
- spec/dnb_nord_spec.rb
|
103
144
|
- spec/nbp_spec.rb
|
104
145
|
- spec/scraper_spec.rb
|
105
146
|
- spec/spec_helper.rb
|
147
|
+
- spec/walutomat_spec.rb
|