fxpotato 1.0.3 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/fxpotato/version.rb +1 -1
- data/lib/fxpotato.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb8890704ee0761a1495035f28e01fc790923a3c
|
4
|
+
data.tar.gz: 835441cd4b04471b01771d689974ee4c9e9099b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69b6b6810b59d4daa04449092adf9cc83321418b65c26be46fccf0be5451e9f4d0add043b05b1900f80cd8d6e0eaf45b9ab40405686a861f0d53ade133b6324e
|
7
|
+
data.tar.gz: b17104b54ed1f792ba0ec3f5727c5cd2ece166b10fbc2d43fbca9770c04bc15e9458c5b69fe3592f784f4794c871cd7175e84da696d9a9942b598e8570898f79
|
data/README.md
CHANGED
@@ -20,8 +20,22 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
$ gem install fxpotato
|
22
22
|
|
23
|
-
|
23
|
+
### Configuration
|
24
|
+
FxPotato takes rates from the [ECB website](http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml).
|
25
|
+
|
26
|
+
To change the feed, set the `FXPOTATO_DATA_SOURCE_URL` environment variable to the new URL, and if the structure of the xml is different (or indeed not XML at all, which is also totes cool), set `FxPotato.repo` to equal an instance of a custom class of your own writing for locating rates in the new structure. Make sure to set `FxPotato.repo = YourClass.new` before you use the other functionality in `FxPotato`.
|
27
|
+
|
28
|
+
The `repo` class you write must implement the `find` method with this signature:
|
29
|
+
|
30
|
+
```
|
31
|
+
def find(date = Date object, currency = Currency key, e.g. 'GBP')
|
32
|
+
// your wonderful code here
|
33
|
+
end
|
34
|
+
```
|
24
35
|
|
36
|
+
If using the crontab functionality, configure your own schedule by editing the `config/schedule.rb` file, as per the [whenever documentation](https://github.com/javan/whenever#example-schedulerb-file).
|
37
|
+
|
38
|
+
## Usage
|
25
39
|
### CLI
|
26
40
|
Get foreign exchange rates on the command line with the following command:
|
27
41
|
|
data/lib/fxpotato/version.rb
CHANGED
data/lib/fxpotato.rb
CHANGED
@@ -6,9 +6,14 @@ require 'fxpotato/rate_fetcher'
|
|
6
6
|
require 'fxpotato/rate_calculator'
|
7
7
|
require 'fxpotato/fxrate'
|
8
8
|
require "fxpotato/railtie" if defined?(Rails)
|
9
|
+
require 'date'
|
9
10
|
|
10
11
|
module FxPotato
|
11
12
|
def self.at(date, base_key, target_key)
|
13
|
+
base_key = upcase_if_not_nil(base_key)
|
14
|
+
target_key = upcase_if_not_nil(target_key)
|
15
|
+
date ||= Date.today
|
16
|
+
|
12
17
|
base_rate = RateStore.get(self.repo, date, base_key)
|
13
18
|
target_rate = RateStore.get(self.repo, date, target_key)
|
14
19
|
|
@@ -29,6 +34,10 @@ module FxPotato
|
|
29
34
|
RateFetcher.fetch(Paths.data_source_url, destination)
|
30
35
|
end
|
31
36
|
|
37
|
+
def self.upcase_if_not_nil(str)
|
38
|
+
str.nil? ? nil : str.upcase
|
39
|
+
end
|
40
|
+
|
32
41
|
module_function
|
33
42
|
def repo; @repo ||= XmlRepo.new end
|
34
43
|
def repo= v; @repo = v end
|