ExchangeRateVlad 0.0.1 → 0.0.2
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/ExchangeRateVlad.rb +35 -5
- 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: 78247f9db9219e29e9fb48fcd697da80d7e19355
|
|
4
|
+
data.tar.gz: 38724bf2d179709c293303e0edb1ea2b597f2d8d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0412d566a7b4dfefd348fb2b0d12fd8e7e16d8b6c7867d931342ee7eb01874042585ffeaf2a6270c282ff2b57170f4cddea7a82f41350d38267a88e9a21ce7e6
|
|
7
|
+
data.tar.gz: 871c781e24012e1842899dc4ee0e84b35c4a303067e08c3727090a6431eec67dfb501b0884dc57abc4bf432e0ccd367479fdc2361a37bc514c8a683103378b1d
|
data/lib/ExchangeRateVlad.rb
CHANGED
|
@@ -2,15 +2,45 @@ class Converter
|
|
|
2
2
|
require 'nokogiri'
|
|
3
3
|
@@doc
|
|
4
4
|
def init(file)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
if file.start_with?('http://') || file.start_with?('https://')
|
|
6
|
+
require 'open-uri'
|
|
7
|
+
begin
|
|
8
|
+
@@doc = Nokogiri::XML(open(file))
|
|
9
|
+
rescue
|
|
10
|
+
p "Unable to open location"
|
|
11
|
+
return false
|
|
12
|
+
end
|
|
13
|
+
else
|
|
14
|
+
begin
|
|
15
|
+
f = File.open(file)
|
|
16
|
+
@@doc = Nokogiri::XML(f)
|
|
17
|
+
f.close
|
|
18
|
+
rescue
|
|
19
|
+
p 'Unable to open Location'
|
|
20
|
+
return false
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
return true
|
|
8
24
|
end
|
|
9
25
|
def at(date, c1, c2)
|
|
10
26
|
d = date.strftime("%Y-%m-%d")
|
|
11
27
|
r = @@doc.css('Cube Cube[@time="'+d+'"]')
|
|
12
|
-
|
|
13
|
-
|
|
28
|
+
if r.size==0
|
|
29
|
+
p 'No data for the specified time of exchange rate: ' + d
|
|
30
|
+
return -1
|
|
31
|
+
end
|
|
32
|
+
begin
|
|
33
|
+
er1 = r.at_css('[@currency="'+c1+'"]')['rate'].to_f
|
|
34
|
+
rescue
|
|
35
|
+
p 'Something is wrong with this currency: ' + c1
|
|
36
|
+
return -1
|
|
37
|
+
end
|
|
38
|
+
begin
|
|
39
|
+
er2 = r.at_css('[@currency="'+c2+'"]')['rate'].to_f
|
|
40
|
+
rescue
|
|
41
|
+
p 'Something is wrong witht this currency: ' + c2
|
|
42
|
+
return -1
|
|
43
|
+
end
|
|
14
44
|
return er2/er1
|
|
15
45
|
end
|
|
16
46
|
end
|