riksbank_currency 0.1.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9cb06cc185f232c081fab9056bf2332c9ded9fb
4
- data.tar.gz: 36ae9d4767b38845cc27aa9e244892c64a47ceda
3
+ metadata.gz: ff68a1ec03900b93f309ef1314e2977686c84f76
4
+ data.tar.gz: 10a41e49061cd1d6b4e97ffd99c5522fedf98c8d
5
5
  SHA512:
6
- metadata.gz: b4fb912717f93c4176b426793ac97c9e4595b6d595f9d2ead159ca9efa91ade61fcbca2a2d6f293df78b0daf723f5df5528f57f7374f44760cf037be15748a53
7
- data.tar.gz: 46aba20322e6226a4802f8c0026b6cfc8495b316b29fdc7095d5a0edd1d84bb42f1a8e23da7b5d79c6e82520d46804ff9b75e88fbfa4f075de2753ef226e8c3d
6
+ metadata.gz: 4e5109179f68b0d75482f8caddca6c830a7a0fb4b2ff2418ccbee6d72bbb406483399861495cf246a90959adda205ec5e2fc2f0568394423806561aa42a20d3d
7
+ data.tar.gz: f68f82dadb2d0660d857a66deeaaff455b7a12942d8998c5b9940ecb94418f398ffe16c6ebfb92615e6eba446747ef95085de24caf3605579a49f8ad4270ad10
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Riksbank Exchange Rates
2
2
 
3
- Simple wrapper for Riksbank API that returns currency exchange rates for the specific date.
3
+ Simple wrapper for Riksbank API that returns currency exchange rates for specific date.
4
4
 
5
5
 
6
6
  ## Installation
@@ -29,15 +29,15 @@ Or install it yourself as:
29
29
 
30
30
  Initializer options:
31
31
 
32
- * `date` - the day for which we want to get exchange rates. It should be `Date` object
33
- * `base` - base currency (by default `SEK`)
32
+ * `date` - specific date we want to get exchange rates for. It should be a valid `Date` object
33
+ * `base` - base currency (`SEK` is used by default)
34
34
  * `rates` - you can pass your own hash with rates. Can be useful for caching purposes
35
35
 
36
36
 
37
37
  ### Retrieve a specific rate
38
38
 
39
39
  ```ruby
40
- # how many euros in one american dollar?
40
+ # How many euros in one american dollar?
41
41
  bank.rate('USD', 'EUR').to_f # => 0.80607
42
42
 
43
43
  # by default it converts to SEK
@@ -56,42 +56,48 @@ Get all rates
56
56
  bank.rates # => { 'NOK' => 105.556298, 'INR' => 13.619511, … }
57
57
  ```
58
58
 
59
- ### Bank days and holidays
59
+ ### Rates from holidays / weekends
60
60
 
61
- During the holidays or weekends bank doesn't change exchange rates. It means that
62
- bank doesn't have exchange rates for Saturday or Christmas.
61
+ Exchange rates are not changed during holidays or weekends.
62
+ If you query bank API directly, you will get an empty hash in response.
63
63
 
64
- Also, another problem in the current day. Bank refreshes rates twice per day (morning and evening).
65
- So, therefore at 3 o'clock of morning bank doensn't have fresh rates and we should use
66
- rates from prevoius day.
67
-
68
- This gem deals with all of this problems:
64
+ To avoid that, this gem provides last known rates:
69
65
 
70
66
  ```ruby
71
- # 20.01.2018 is Saturday, bank doesn't work at this day
67
+ # 20.01.2018 is Saturday, bank is closed
72
68
  holiday_bank = RiksbankCurrency::Rates.new(date: Date.new(2018, 1, 20))
73
69
 
74
- # rates will be got from Friday!
70
+ # Last known rates will be fetched instead (from Friday).
75
71
  holiday_bank.rate_date # Fri, 19 Jan 2018
76
-
77
-
78
-
79
-
80
- # imagine that we do it at night
72
+ ````
73
+
74
+ ### Riksbank updates rates twice a day (in the morning and in the evening)
75
+
76
+ If you try to fetch rates at 03.00 in the morning, then you will get an empty hash from the bank.
77
+ Therefore gem will return rates from a previous date.
78
+
79
+ ```ruby
81
80
  # Time.current => Fri, 26 Jan 2018 03:00:00 UTC +00:00
82
81
  morning_bank = RiksbankCurrency::Rates.new
83
82
 
84
- # it is too early, bank doensn't work at this time
85
- # let's use yesterday rates
83
+ # It's too early, bank doensn't work at this time
84
+ # Yesterday's rates will be used instead
86
85
  morning_bank.rate_date # Thu, 25 Jan 2018
87
86
  ```
88
87
 
89
- ### Available currencies
88
+ #### Default currencies
90
89
 
91
- Pay attention to check available currencies at [official bank page](http://www.riksbank.se/en/Interest-and-exchange-rates/Series-for-web-services/).
90
+ ```ruby
91
+ %w(AUD BRL CAD CHF CNY CZK DKK EUR GBP HKD HUF IDR INR ISK JPY
92
+ KRW MAD MXN NOK NZD PLN RUB SAR SGD THB TRY USD ZAR)
93
+ ```
94
+
95
+ ### Additional currencies
92
96
 
93
- By default this gem uses only existing currencies for 2018. For example, FIM (Finland Marka)
94
- has rates only till 2002 and it doesn't exist anymore in 2018.
97
+ Check bank page to get a fresh list of provided currencies [official bank page](http://www.riksbank.se/en/Interest-and-exchange-rates/Series-for-web-services/).
98
+
99
+ By default this gem is only using existing currencies from 2018.
100
+ For example, FIM (Finland Marka) has published rates until 2002.
95
101
 
96
102
  So, if you wanna get information about FIM exchange rate in 2001 you should
97
103
  change the gem defaults:
@@ -106,13 +112,6 @@ change the gem defaults:
106
112
  today_bank.rate('FIM') # nil
107
113
  ```
108
114
 
109
- #### Default currencies
110
-
111
- ```ruby
112
- %w(AUD BRL CAD CHF CNY CZK DKK EUR GBP HKD HUF IDR INR ISK JPY
113
- KRW MAD MXN NOK NZD PLN RUB SAR SGD THB TRY USD ZAR)
114
- ```
115
-
116
115
  ## Legal
117
116
 
118
117
  The author of this gem is not affiliated with the Riksbank.
@@ -3,8 +3,8 @@ module RiksbankCurrency
3
3
  #
4
4
  # @see https://swea.riksbank.se/sweaWS/docs/api/call/getInterestAndExchangeRates.htm
5
5
  #
6
- # IMPORTANT! The date should be less than current date. To get rates for today
7
- # see at TodayFetcher
6
+ # IMPORTANT! The date should be less than current date.
7
+ # To get current rates - check TodayFetcher
8
8
  class DateFetcher
9
9
  def initialize(date)
10
10
  @date = date
@@ -33,11 +33,11 @@ module RiksbankCurrency
33
33
  @rates ||= fetcher.to_hash
34
34
  end
35
35
 
36
- # Sometimes date passed to the initializer differs from real exchange date.
37
- # It causes from holidays, weekends and etc.
36
+ # Sometimes date passed to the initializer is different from last available exchange date.
37
+ # It could be because of holidays, weekends or bank closing hours.
38
38
  #
39
39
  # For example, if we want to get rates for the `1st of January 2018` then rate date
40
- # will be `27th of December 2017`
40
+ # will be `27th of December 2017`, because `1st of January` is a holiday.
41
41
  # @return [Date]
42
42
  def rate_date
43
43
  @rate_date ||= fetcher.rate_date
@@ -1,3 +1,3 @@
1
1
  module RiksbankCurrency
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riksbank_currency
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Yakovlev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-26 00:00:00.000000000 Z
11
+ date: 2018-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri