cnb_rates 0.0.5 → 0.0.6

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cnb_rates.rb +10 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28930db5006659dfa49ff3f075b1c0b9e21ffdbe
4
- data.tar.gz: 56f5fa96cac3f5ecb76fed8dc05b27b43060779e
3
+ metadata.gz: e3ddfd2dce492133c9beff13d39c2f1d898d5285
4
+ data.tar.gz: 29b2dfd686f61547bcea42a11b8057c13da09eed
5
5
  SHA512:
6
- metadata.gz: c6463f75593f07d3fde2fdc76679ad8dc946f1f9a024275b00040f2d8c36d79090f9235767b48c1b299b17130a3588160b7aaaf0a0f390f3a5a3b925c99c47af
7
- data.tar.gz: 4b4cdebc06b35f7c3977503eac757ef100194b14a581455ec7c0fd2fdbfc3a2557999d4d5893990cac4e9ce3ddce3b4bee719cda25e9604d941830a2a37c4859
6
+ metadata.gz: 67eaed058fa4a3d6ee6d7fd93f60b76ec090e867ef92f0fc69b529a3b778796135dae2915097dec6d587dc0534d3bb70dde05df65055c72ab31b28b67fc6b9c8
7
+ data.tar.gz: 8063b26e07f784788293daafe451deb632c1b88eb85631f15cd7de9bdef4ec763f96377b330403db325d0cbb2f50eb7b93eb626f1473a5f589f8d4da0242923b
data/lib/cnb_rates.rb CHANGED
@@ -14,6 +14,7 @@ class CNBRates
14
14
  def initialize(options = {})
15
15
  @date = options[:date] || Date.today
16
16
  @filename = options[:filename] || ''
17
+ @big_decimals = options[:big_decimals] || false
17
18
  @date = @date.strftime('%d.%m.%Y')
18
19
  @currency_list = []
19
20
 
@@ -22,7 +23,11 @@ class CNBRates
22
23
 
23
24
  def rate(currency, amount=1)
24
25
  method_name = currency.downcase.to_sym
25
- rate = respond_to?(method_name) ? send(method_name) : 1.0
26
+ rate = if respond_to?(method_name) then
27
+ send(method_name)
28
+ else
29
+ @big_decimals ? BigDecimal.new(1) : 1.0
30
+ end
26
31
  rate * amount
27
32
  end
28
33
 
@@ -34,9 +39,11 @@ class CNBRates
34
39
  lines.each_line do |line|
35
40
  split_line = line.split('|')
36
41
 
37
- volume = BigDecimal.new split_line[2]
42
+ volume = @big_decimals ? BigDecimal.new(split_line[2]) : split_line[2].to_f
38
43
  currency_code = split_line[3].downcase
39
- currency_rate = BigDecimal.new split_line[4].gsub(',', '.')
44
+
45
+ currency_rate_str = split_line[4].gsub(',', '.')
46
+ currency_rate = @big_decimals ? BigDecimal.new(currency_rate_str) : currency_rate_str.to_f
40
47
  currency_rate = volume == 1 ? currency_rate : currency_rate / volume
41
48
 
42
49
  self.class.send(:define_method, "#{currency_code}") do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnb_rates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaromír Červenka