fafx 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -3
- data/fafx.gemspec +1 -1
- data/lib/fafx.rb +2 -1
- data/lib/fafx/{er.rb → core.rb} +4 -4
- data/lib/fafx/date_error.rb +17 -0
- data/lib/fafx/exchange_rate.rb +13 -6
- data/lib/fafx/version.rb +1 -1
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac94bcd60e427e6278a8e556d2c93b7e29bc8775
|
4
|
+
data.tar.gz: b89876e35bb697d9c3c5c90a4086f85a2737b074
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06a38db8b00a0512ba636c73669704f33e803f05b501e51f8cd9065b749ba79ff4924d8d5c9c804ce8a99b385d75304e852465140f8e1cbc4ab06ef75fbfe74c
|
7
|
+
data.tar.gz: 5cce51dd705027f9893ec9ce160435c068e73da8466bedefc8261a42e0d9616cfaca5741072ab99fd68feaba311f3a52380f5228dd990c121fa0b832c776d786
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -39,7 +39,7 @@ Fafx::ExchangeRate.most_recent
|
|
39
39
|
# => {"USD"=>1.1571, "JPY"=>128.54, "BGN"=>1.9558, "CZK"=>25.648, ...}
|
40
40
|
```
|
41
41
|
|
42
|
-
The `at` function may raise a `
|
42
|
+
The `at` function may raise a `DateError` or `CurrencyError` exception, should the date or currency be unavailable.
|
43
43
|
|
44
44
|
## Updating the exchange rates data
|
45
45
|
|
@@ -52,7 +52,7 @@ You can update the exchange rates values either via the **CLI**, **Rake task** o
|
|
52
52
|
```ruby
|
53
53
|
require 'fafx'
|
54
54
|
|
55
|
-
Fafx::ExchangeRate.
|
55
|
+
Fafx::ExchangeRate.update_data
|
56
56
|
```
|
57
57
|
|
58
58
|
---
|
@@ -63,4 +63,4 @@ One can also schedule a **cron job** (the following example fetches the data eve
|
|
63
63
|
* * * * * . ~/.zshrc; fafx -u
|
64
64
|
```
|
65
65
|
|
66
|
-
Note: `. ~/.zshrc` is used to load the environment with the Ruby gems path, because cron uses `PATH=/usr/bin:/usr/sbin` and `SHELL=/usr/bin/sh by default
|
66
|
+
Note: `. ~/.zshrc` is used to load the environment with the Ruby gems path, because cron uses `PATH=/usr/bin:/usr/sbin` and `SHELL=/usr/bin/sh` by default. Fonts: [here](http://man7.org/linux/man-pages/man5/crontab.5.html) and [here](http://www.adminschoice.com/crontab-quick-reference)
|
data/fafx.gemspec
CHANGED
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
23
23
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
24
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
-
spec.add_runtime_dependency 'nokogiri', '~> 1.8.2'
|
25
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.8', '>= 1.8.2'
|
26
26
|
end
|
data/lib/fafx.rb
CHANGED
data/lib/fafx/{er.rb → core.rb}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
|
-
class
|
3
|
+
class Core
|
4
4
|
attr_reader :rates, :dates, :currencies
|
5
5
|
def initialize
|
6
6
|
data = load_data
|
@@ -10,8 +10,8 @@ class ER
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def rates_at(date, curr)
|
13
|
-
raise
|
14
|
-
raise
|
13
|
+
raise Fafx::DateError, 'Date not available' unless @dates.include?(date)
|
14
|
+
raise Fafx::CurrencyError, "#{curr} not found" unless @currencies.include?(curr)
|
15
15
|
@rates[date][curr]
|
16
16
|
end
|
17
17
|
|
@@ -19,7 +19,7 @@ class ER
|
|
19
19
|
|
20
20
|
def load_data
|
21
21
|
rates = "#{File.join(File.dirname(__FILE__))}/rates.yaml"
|
22
|
-
Fafx::ExchangeRate.
|
22
|
+
Fafx::ExchangeRate.update_data unless File.exist?(rates)
|
23
23
|
YAML.load_file(rates)
|
24
24
|
end
|
25
25
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Fafx
|
2
|
+
class DateError < StandardError
|
3
|
+
attr_reader :message
|
4
|
+
def initialize(message)
|
5
|
+
super
|
6
|
+
@message = message
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class CurrencyError < StandardError
|
11
|
+
attr_reader :message
|
12
|
+
def initialize(message)
|
13
|
+
super
|
14
|
+
@message = message
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/fafx/exchange_rate.rb
CHANGED
@@ -1,33 +1,40 @@
|
|
1
1
|
module Fafx
|
2
2
|
module ExchangeRate
|
3
3
|
def at(date, base, other)
|
4
|
-
|
4
|
+
case date.wday
|
5
|
+
when 6 # Saturday
|
6
|
+
date -= 1
|
7
|
+
when 0 # Sunday
|
8
|
+
date -= 2
|
9
|
+
end
|
10
|
+
|
11
|
+
ex_rates = Core.new
|
5
12
|
base = ex_rates.rates_at(date.to_s, base)
|
6
13
|
other = ex_rates.rates_at(date.to_s, other)
|
7
14
|
other / base
|
8
15
|
end
|
9
16
|
|
10
17
|
def currencies_available
|
11
|
-
|
18
|
+
Core.new.currencies
|
12
19
|
end
|
13
20
|
|
14
21
|
def dates_available
|
15
|
-
|
22
|
+
Core.new.dates
|
16
23
|
end
|
17
24
|
|
18
25
|
def most_recent
|
19
|
-
ex_rates =
|
26
|
+
ex_rates = Core.new
|
20
27
|
first_date = ex_rates.dates.first
|
21
28
|
ex_rates.rates[first_date]
|
22
29
|
end
|
23
30
|
|
24
|
-
def
|
31
|
+
def update_data
|
25
32
|
DataFetcher.save_to_disk
|
26
33
|
end
|
27
34
|
module_function :at,
|
28
35
|
:currencies_available,
|
29
36
|
:dates_available,
|
30
37
|
:most_recent,
|
31
|
-
:
|
38
|
+
:update_data
|
32
39
|
end
|
33
40
|
end
|
data/lib/fafx/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fafx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Kair
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -57,6 +57,9 @@ dependencies:
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
- - ">="
|
60
63
|
- !ruby/object:Gem::Version
|
61
64
|
version: 1.8.2
|
62
65
|
type: :runtime
|
@@ -64,6 +67,9 @@ dependencies:
|
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
69
|
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.8'
|
72
|
+
- - ">="
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: 1.8.2
|
69
75
|
description: Lib and CLI to get exchange rates from the European Central Bank
|
@@ -87,8 +93,9 @@ files:
|
|
87
93
|
- bin/setup
|
88
94
|
- fafx.gemspec
|
89
95
|
- lib/fafx.rb
|
96
|
+
- lib/fafx/core.rb
|
90
97
|
- lib/fafx/data_fetcher.rb
|
91
|
-
- lib/fafx/
|
98
|
+
- lib/fafx/date_error.rb
|
92
99
|
- lib/fafx/exchange_rate.rb
|
93
100
|
- lib/fafx/version.rb
|
94
101
|
homepage: https://github.com/frankkair/fafx
|