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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4002cca6fd0bbfa36251d56afd536f7810553dd7
4
- data.tar.gz: c1f9033d228291f80ebd9d1d54d2f4c3a0c74039
3
+ metadata.gz: fb8890704ee0761a1495035f28e01fc790923a3c
4
+ data.tar.gz: 835441cd4b04471b01771d689974ee4c9e9099b0
5
5
  SHA512:
6
- metadata.gz: ad9099b8cec6142315b7e82c030d6f65e9daedffff362fd96578c8e67d8198a062f55bb4f2e64b82034e2875948c3f6712e353101010422b8dfd1729f2a18a20
7
- data.tar.gz: ee4fc398cc0cf75678735128af6eeffa8cecbc7733af9efefa8fa7b2f1e939ab722b1e481ff029c8a02583910facb9a63e462e6c960b5e1f5bdfe1c40403f549
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
- ## Usage
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
 
@@ -1,3 +1,3 @@
1
1
  module FxPotato
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.1'
3
3
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fxpotato
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liam Stupid Name Humphreys