national_bank_of_romania 0.0.2 → 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8945982200be01df73f0dd3c405260cb22150a9
4
+ data.tar.gz: 8ed9060ab6dfcd556b0fdc1f6ee0c6ce4a8a999f
5
+ SHA512:
6
+ metadata.gz: fe5ced0700b28f650f335b3726ef5f9a7462c948d2ab020a03a8ba28ad8b59ccce17c158e168acfd10e14b23ce686aff3891bff7db68f5ddf0c8654402873e6f
7
+ data.tar.gz: 2cf6102f8ba32ecaf09e8f39f7243dab057797e43732dd5379c94633a73ffc63605dd0bfdb8637c7000886b0491184c08ad3ba9c2303b0285e4616628f5faac9
data/lib/bank.rb CHANGED
@@ -2,7 +2,7 @@ require "money"
2
2
  module NationalBankOfRomania
3
3
 
4
4
  class Bank < ::Money::Bank::VariableExchange
5
- attr_accessor :last_updated
5
+ attr_accessor :last_updated, :rates_updated_at
6
6
 
7
7
  RATES_URL = "http://www.bnro.ro/nbrfxrates.xml"
8
8
  CURRENCIES = %w(AED AUD BGN BRL CAD CHF CNY CZK DKK EGP EUR GBP HUF INR JPY
@@ -18,8 +18,10 @@ module NationalBankOfRomania
18
18
  add_rate("RON", rate[:currency], rate[:value])
19
19
  end
20
20
 
21
+
21
22
  add_rate("RON", "RON", 1)
22
23
  @last_updated = Time.now
24
+ @rates_updated_at = Time.parse(parser.date(path_to_file))
23
25
  end
24
26
 
25
27
  def exchange_with(from, to_currency)
@@ -33,11 +35,11 @@ module NationalBankOfRomania
33
35
  end
34
36
  _to_currency_ = Money::Currency.wrap(to_currency)
35
37
 
36
- fractional = BigDecimal.new(from.fractional.to_s) /
38
+ cents = BigDecimal.new(from.cents.to_s) /
37
39
  (BigDecimal.new(from.currency.subunit_to_unit.to_s) /
38
40
  BigDecimal.new(_to_currency_.subunit_to_unit.to_s))
39
41
 
40
- ex = fractional * BigDecimal.new(rate.to_s)
42
+ ex = cents * BigDecimal.new(rate.to_s)
41
43
  ex = ex.to_f
42
44
  ex = if block_given?
43
45
  yield ex
@@ -1,3 +1,3 @@
1
1
  module NationalBankOfRomania
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/parser.rb CHANGED
@@ -10,16 +10,23 @@ module NationalBankOfRomania
10
10
  end
11
11
 
12
12
  def records(cache)
13
+ @records = doc(cache).root.elements[1].elements[2].elements
14
+ formatted_records
15
+ end
16
+
17
+ def date(cache)
18
+ date = doc(cache).root.elements[0].elements[1].children[0].text
19
+ end
20
+
21
+ def doc(cache)
13
22
  source = !!cache ? cache : url
14
23
  doc = Nokogiri::XML(open(source))
15
- @records = doc.root.elements[1].elements[2].elements
16
- formatted_records
17
24
  end
18
25
 
19
26
  private
20
27
  def formatted_records
21
28
  @records.map do |row|
22
- { currency: row.attribute("currency").value, value: row.text.to_f }
29
+ { :currency => row.attribute("currency").value, :value => row.text.to_f }
23
30
  end
24
31
  end
25
32
  end
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.homepage = ""
14
14
 
15
15
  gem.add_dependency "nokogiri", "~> 1.5.6"
16
- gem.add_dependency "money", "~> 5.1.0"
16
+ gem.add_dependency "money", "~> 5.0.0"
17
17
 
18
18
  gem.add_development_dependency "rspec", ">= 2.12.0"
19
19
  gem.add_development_dependency "rake"
data/spec/bank_spec.rb CHANGED
@@ -50,13 +50,18 @@ describe "Bank" do
50
50
  bank2.should_not eq(bank3)
51
51
  end
52
52
 
53
+ it "should set rates_updated_at when the rates are updated" do
54
+ @bank.update_rates(@feed)
55
+ @bank.rates_updated_at.should eq(Time.parse('2013-01-17'))
56
+ end
57
+
53
58
  context "#exchange" do
54
59
  it "calls 'exchange_with' with the correct params" do
55
60
  @bank.update_rates(@feed)
56
61
 
57
62
  from = Money.new(100, "RON")
58
63
  to = Money::Currency.wrap("USD")
59
- money = double(:fractional => 324, :currency => "USD")
64
+ money = double(:cents => 324, :currency => "USD")
60
65
 
61
66
  @bank.should_receive(:exchange_with).with(from, to).and_return(money)
62
67
  @bank.exchange(100, "RON", "USD")
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: national_bank_of_romania
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Vlad Suciu
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-22 00:00:00.000000000 Z
11
+ date: 2013-09-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: nokogiri
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,49 +27,43 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: money
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
37
- version: 5.1.0
33
+ version: 5.0.0
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
45
- version: 5.1.0
40
+ version: 5.0.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: 2.12.0
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: 2.12.0
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  description: This gem provides the ability to download the exchange rates from the
@@ -104,27 +95,26 @@ files:
104
95
  - spec/spec_helper.rb
105
96
  homepage: ''
106
97
  licenses: []
98
+ metadata: {}
107
99
  post_install_message:
108
100
  rdoc_options: []
109
101
  require_paths:
110
102
  - lib
111
103
  required_ruby_version: !ruby/object:Gem::Requirement
112
- none: false
113
104
  requirements:
114
- - - ! '>='
105
+ - - '>='
115
106
  - !ruby/object:Gem::Version
116
107
  version: '0'
117
108
  required_rubygems_version: !ruby/object:Gem::Requirement
118
- none: false
119
109
  requirements:
120
- - - ! '>='
110
+ - - '>='
121
111
  - !ruby/object:Gem::Version
122
112
  version: '0'
123
113
  requirements: []
124
114
  rubyforge_project:
125
- rubygems_version: 1.8.23
115
+ rubygems_version: 2.0.3
126
116
  signing_key:
127
- specification_version: 3
117
+ specification_version: 4
128
118
  summary: This gem provides the ability to download the exchange rates from the National
129
119
  Bank of Romania and it is compatible with the money gem.
130
120
  test_files: