fx_fetcher 0.0.2 → 0.0.3
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/README.md +17 -2
- data/fx_fetcher-0.0.2.gem +0 -0
- data/lib/fx_fetcher/version.rb +1 -1
- data/lib/fx_fetcher.rb +4 -3
- data/spec/fx_fetcher_spec.rb +7 -0
- data/spec/spec_helper.rb +8 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 417daac6594c715d6fac95bec4a56a010f7833ed
|
4
|
+
data.tar.gz: d128adb36727241d3ca53940abd9a50ce827528b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96e63e5fb42b21e71efb523a8ea8219d07298c8ba56349e6c14f96a5a5942eeb489ce7eb1fa1796b7c5c819dcc736784e247c9c06c9e5c47be331129fb7d5416
|
7
|
+
data.tar.gz: 986d4fe69f8fbf03a6af1e6ec10908f043ca5e0dfadf971afc44ef9939ceca1845396a38f14f52d0270b9c3924176e8ace674ded99a9ad548f05791858f97a84
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# FxFetcher
|
2
2
|
|
3
|
-
|
3
|
+
FxFetcher is a gem that calculates the fx rate for a currency pair eg. EUR/USD. There is a basic demo at http://knox-fx.herokuapp.com/ to show how you could use it.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,7 +20,22 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
FxFetcher is currently quite basic and requires a model to be set up like so:
|
24
|
+
|
25
|
+
t.date :rate_date
|
26
|
+
t.string :base_currency
|
27
|
+
t.string :counter_currency
|
28
|
+
t.decimal :rate
|
29
|
+
|
30
|
+
In your model type ```include FxFetcher``` and the following commands are available:
|
31
|
+
|
32
|
+
```ModelName.at(Date.today,'GBP','USD')``` to calculate the fx rate
|
33
|
+
|
34
|
+
```ModelName.currencies``` to get a list of possible currencies
|
35
|
+
|
36
|
+
```ModelName.valid_amount?(amount)``` to check if amount is non text and greater than zero
|
37
|
+
|
38
|
+
I plan to turn this into a Rails engine that will automate the setup of a database by just requiring the command ```rake db:migrate`
|
24
39
|
|
25
40
|
## Contributing
|
26
41
|
|
Binary file
|
data/lib/fx_fetcher/version.rb
CHANGED
data/lib/fx_fetcher.rb
CHANGED
@@ -7,14 +7,14 @@ module FxFetcher
|
|
7
7
|
|
8
8
|
module ClassMethods
|
9
9
|
def at(date, base, counter)
|
10
|
-
if
|
10
|
+
if currencies_present_for_date(date)
|
11
11
|
search_for_rate(date, base, counter)
|
12
12
|
else
|
13
13
|
"No rates available for this date"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
# helper to create list of available currencies
|
17
|
+
# helper to create list of available currencies to use in form
|
18
18
|
def currencies
|
19
19
|
currencies = []
|
20
20
|
rates_for_date = self.where(rate_date: self.first.rate_date)
|
@@ -29,13 +29,14 @@ module FxFetcher
|
|
29
29
|
|
30
30
|
private
|
31
31
|
|
32
|
-
def
|
32
|
+
def currencies_present_for_date(date)
|
33
33
|
self.where(rate_date: date).present?
|
34
34
|
end
|
35
35
|
|
36
36
|
def search_for_rate(date, base, counter)
|
37
37
|
rates_for_date = self.where(rate_date: date)
|
38
38
|
exchange_rate = rates_for_date.each do |rate|
|
39
|
+
return 1 if base == counter
|
39
40
|
return rate.rate if rate.base_currency == base && rate.counter_currency == counter
|
40
41
|
return (1/rate.rate).round(4) if rate.base_currency == counter && rate.counter_currency == base
|
41
42
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fx_fetcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Knox
|
@@ -64,9 +64,12 @@ files:
|
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
|
+
- fx_fetcher-0.0.2.gem
|
67
68
|
- fx_fetcher.gemspec
|
68
69
|
- lib/fx_fetcher.rb
|
69
70
|
- lib/fx_fetcher/version.rb
|
71
|
+
- spec/fx_fetcher_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
70
73
|
homepage: ''
|
71
74
|
licenses:
|
72
75
|
- MIT
|
@@ -91,4 +94,6 @@ rubygems_version: 2.4.3
|
|
91
94
|
signing_key:
|
92
95
|
specification_version: 4
|
93
96
|
summary: A tool to fetch fx data from a database
|
94
|
-
test_files:
|
97
|
+
test_files:
|
98
|
+
- spec/fx_fetcher_spec.rb
|
99
|
+
- spec/spec_helper.rb
|