central_bank_of_russia 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ == 0.1.0 (September 1 2012)
2
+
3
+ * Initial gem release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Alexey 'codesnik' Trofimenko
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ == Introduction
2
+
3
+ This gem downloads the exchange rates from the Central Bank of Russia.
4
+
5
+ == Installation
6
+
7
+ $ gem install central_bank_of_russia
8
+
9
+ == Dependencies
10
+
11
+ * nokogiri
12
+ * money
13
+
14
+ == Usage
15
+
16
+ bank = CentralBankOfRussia.new.update_rates(Date.today)
17
+ Money.default_bank = CentralBankOfRussia.new.update_rates(Date.today)
18
+ 1.to_money("USD").exchange_to("RUB")
19
+ bank.exchange_with("100 RUB".to_money, "EUR")
20
+
21
+ == Copyright
22
+
23
+ Copyright (c) 2012 Eviterra. See LICENSE for details.
@@ -0,0 +1,35 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'money'
4
+
5
+ class CentralBankOfRussia < Money::Bank::VariableExchange
6
+
7
+ CBR_RATES_URL = 'http://www.cbr.ru/scripts/XML_daily.asp'
8
+
9
+ def update_rates(date=Date.today)
10
+ rates = parse_rates(open(CBR_RATES_URL + '?date_req=' + date.strftime('%d/%m/%Y')))
11
+ rates.each do |currency, rate|
12
+ begin
13
+ add_rate currency, 'RUB', rate
14
+ add_rate 'RUB', currency, 1/rate
15
+ rescue Money::Currency::UnknownCurrency
16
+ # skip
17
+ end
18
+ end
19
+ self
20
+ end
21
+
22
+ def parse_rates(doc_string)
23
+ doc = Nokogiri::XML(doc_string)
24
+ rates = {}
25
+ doc.xpath('//Valute').each do |valute|
26
+ currency = valute.xpath('CharCode').text.upcase
27
+ nominal = valute.xpath('Nominal').text.to_i
28
+ rate = valute.xpath('Value').text.gsub(',', '.').to_f / nominal
29
+ rates[currency] = rate
30
+ end
31
+ rates
32
+ end
33
+ private :parse_rates
34
+
35
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: central_bank_of_russia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexey 'codesnik' Trofimenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: money
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 5.0.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 5.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.0.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.0
62
+ description: This gem reads exchange rates from the Central Bank of Russia website.
63
+ It is compatible with the money gem
64
+ email:
65
+ - aronaxis@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - lib/central_bank_of_russia.rb
71
+ - CHANGELOG.rdoc
72
+ - LICENSE
73
+ - README.rdoc
74
+ homepage: http://github.com/Eviterra/central_bank_of_russia
75
+ licenses: []
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: 1.3.6
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 1.8.24
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Calculates exchange rates based on rates from Central Bank of Russia. Money
98
+ gem compatible.
99
+ test_files: []
100
+ has_rdoc: