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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb55735ff3c285ce9dd9a00b4ea34d92c5af8186
4
- data.tar.gz: 8e3a18734448b9b1fe50cc88e694d8d510fd896e
3
+ metadata.gz: 417daac6594c715d6fac95bec4a56a010f7833ed
4
+ data.tar.gz: d128adb36727241d3ca53940abd9a50ce827528b
5
5
  SHA512:
6
- metadata.gz: f32068257a70c84e8d5d1e1c548d285d48ca82212f2299e9589652d7ad632150363bc05f50e069926e72dd63ae285133472a315054c3afa703c2637bf50e2525
7
- data.tar.gz: 3fe911da29357435a7324515e81c00cd3eea5ebbcdf80cb3fa36f602384caa6cdb6646a70fa27be9e3ed5d7c53dfe3f877f97825db7e1a745d36c0f90c3aa552
6
+ metadata.gz: 96e63e5fb42b21e71efb523a8ea8219d07298c8ba56349e6c14f96a5a5942eeb489ce7eb1fa1796b7c5c819dcc736784e247c9c06c9e5c47be331129fb7d5416
7
+ data.tar.gz: 986d4fe69f8fbf03a6af1e6ec10908f043ca5e0dfadf971afc44ef9939ceca1845396a38f14f52d0270b9c3924176e8ace674ded99a9ad548f05791858f97a84
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # FxFetcher
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
@@ -1,3 +1,3 @@
1
1
  module FxFetcher
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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 currency_present_for_date(date)
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 currency_present_for_date(date)
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
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe FxFetcher do
4
+ it 'does stuff' do
5
+ pending # no code yet
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ # our gem
4
+ require 'fx_fetcher'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
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.2
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