exchanges-rates-nbp 1.0.5 → 1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -1
- data/README.md +34 -25
- data/lib/exchanges/rates.rb +1 -1
- data/lib/exchanges/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0064011f8fc426db087c7944900081ec3df4d974
|
4
|
+
data.tar.gz: 2a69cdfc9fdf0ede6ac3203cd1e85fcbf7f3b975
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16d0199e8baff8ec3b6ff1093bfaa2dd541d830936e30711d7493ec0b998d8a4e476fe20c6b90bcbd3eb043b1703f7f4f6107e79453a0fae6c025582ace24473
|
7
|
+
data.tar.gz: 19bf86af61171ce223c2aa7111c9f0e734fd32b59e5b0bcea3b3425ca67a65dc42d412fd8e4714074623aa261098793e760025521cff791218f52c456789ab59
|
data/CHANGELOG.md
CHANGED
@@ -5,4 +5,5 @@
|
|
5
5
|
1.0.2 best practices according to http://guides.rubygems.org/
|
6
6
|
1.0.3 CHANGELOG, README
|
7
7
|
1.0.4 the base value of currency should be a number
|
8
|
-
1.0.5 bug - base value of currency, tests
|
8
|
+
1.0.5 bug - base value of currency, tests
|
9
|
+
1.0.6 the name of currency for the convenience is converted to utf-8; bug in README - proper name of class
|
data/README.md
CHANGED
@@ -5,50 +5,55 @@ Simple gem that gets exchange rates from the Polish National Bank.
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
|
-
|
8
|
+
----------
|
9
|
+
```bash
|
9
10
|
gem 'exchanges-rates-nbp'
|
10
|
-
|
11
|
+
```
|
11
12
|
And then execute:
|
12
|
-
|
13
|
+
```bash
|
13
14
|
$ bundle
|
14
|
-
|
15
|
+
```
|
15
16
|
Or install it yourself as:
|
16
|
-
|
17
|
+
```bash
|
17
18
|
$ gem install exchanges-rates-nbp
|
18
|
-
|
19
|
+
```
|
19
20
|
## Usage
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
nbp =
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
Basic usage:
|
23
|
+
```ruby
|
24
|
+
nbp = Exchanges::Nbp.new(nil, nil)
|
25
|
+
```
|
26
|
+
parameters:
|
27
27
|
* date - default Date.today, you can pass another valid date
|
28
|
+
* args - optional parameters, currently only one `selected_currencies`, example below
|
28
29
|
|
29
|
-
* args - optional parameters
|
30
30
|
|
31
|
+
Class instance has three important methods
|
32
|
+
* `codes` - returns currency symbols from table,
|
33
|
+
* `published_at` - returns publication date exchange rates,
|
34
|
+
* `rates(currency)` - returns currency rate at indicated date
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
* published_at - returns publication date exchange rates,
|
37
|
-
|
38
|
-
* rates(currency) - returns currency rate at indicated date
|
36
|
+
To get all codes from table call it:
|
37
|
+
```ruby
|
38
|
+
nbp.codes #=> ["THB", "USD", "AUD", "HKD", "CAD", "NZD", "SGD", "EUR", "HUF", "CHF", "GBP", "UAH", "JPY", "CZK", "DKK", "ISK", "NOK", "SEK", "HRK", "RON", "BGN", "TRY", "LTL", "ILS", "CLP", "PHP", "MXN", "ZAR", "BRL", "MYR", "RUB", "IDR", "INR", "KRW", "CNY", "XDR"]
|
39
|
+
```
|
39
40
|
|
41
|
+
To get exchange rate e.g. USD you have to call:
|
42
|
+
```ruby
|
43
|
+
nbp.rates("USD") #=> {:symbol=>"USD", :name=>"dolar amerykański", :base=>1.0, :average_rate=>3.2964}
|
44
|
+
```
|
40
45
|
|
41
46
|
If you interested only selected currencies at indicated day use in this way:
|
42
|
-
|
43
|
-
nbp =
|
44
|
-
|
47
|
+
```ruby
|
48
|
+
nbp = Exchanges::Nbp.new(Date.today - 3, {selected_currencies: ['USD', 'EUR']})
|
49
|
+
```
|
45
50
|
|
46
51
|
Now you can retrieve currency rates for chosen:
|
47
|
-
|
52
|
+
```ruby
|
48
53
|
nbp.codes.each do |c|
|
49
54
|
nbp.rates(c)
|
50
55
|
end
|
51
|
-
|
56
|
+
```
|
52
57
|
|
53
58
|
## Future ideas
|
54
59
|
1. Currency and CurrencyRate model, Sequel/ActiveRecord migration
|
@@ -62,3 +67,7 @@ Now you can retrieve currency rates for chosen:
|
|
62
67
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
68
|
4. Push to the branch (`git push origin my-new-feature`)
|
64
69
|
5. Create a new Pull Request
|
70
|
+
|
71
|
+
|
72
|
+
## License
|
73
|
+
Copyright(c) 2014 Krzysztof Wiesławski, released under the MIT license
|
data/lib/exchanges/rates.rb
CHANGED
@@ -19,7 +19,7 @@ module Exchanges
|
|
19
19
|
def rates(currency)
|
20
20
|
rate = {}
|
21
21
|
rate[:symbol] = xml.xpath("//pozycja[kod_waluty='#{currency}']/kod_waluty/text()").to_s
|
22
|
-
rate[:name] = xml.xpath("//pozycja[kod_waluty='#{currency}']/nazwa_waluty/text()").to_s
|
22
|
+
rate[:name] = xml.xpath("//pozycja[kod_waluty='#{currency}']/nazwa_waluty/text()").to_s.force_encoding('iso-8859-2').encode('utf-8')
|
23
23
|
rate[:base] = xml.xpath("//pozycja[kod_waluty='#{currency}']/przelicznik/text()").to_s.gsub(',', '.').to_f
|
24
24
|
rate[:average_rate] = xml.xpath("//pozycja[kod_waluty='#{currency}']/kurs_sredni/text()").to_s.gsub(',', '.').to_f
|
25
25
|
rate
|
data/lib/exchanges/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exchanges-rates-nbp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- krzysztof.wieslawski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|