fafx 0.1.1 → 0.1.2

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: 00740a9067c4044fd55665b0c61059c090cb1657
4
- data.tar.gz: 61dc5c53fc2d376d850efe43e3397d43f5ab6be5
3
+ metadata.gz: ac94bcd60e427e6278a8e556d2c93b7e29bc8775
4
+ data.tar.gz: b89876e35bb697d9c3c5c90a4086f85a2737b074
5
5
  SHA512:
6
- metadata.gz: 7c3a0cea20e949601b2115f9fd533922d5a81565f576a9903a6d62d0fa237553645d5d423d88f1b4000f172462342560baec3225dccf37d6698dd2cd9c4dda70
7
- data.tar.gz: b22882852ddb68ce273973f90e17b67be2ecfdfcd7a23d8543c048c63193d64ffca22ce9e801a1b9cef71cd0f2252aaea388c289acb810926a5180e778a26b21
6
+ metadata.gz: 06a38db8b00a0512ba636c73669704f33e803f05b501e51f8cd9065b749ba79ff4924d8d5c9c804ce8a99b385d75304e852465140f8e1cbc4ab06ef75fbfe74c
7
+ data.tar.gz: 5cce51dd705027f9893ec9ce160435c068e73da8466bedefc8261a42e0d9616cfaca5741072ab99fd68feaba311f3a52380f5228dd990c121fa0b832c776d786
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fafx (0.1.0)
4
+ fafx (0.1.1)
5
5
  nokogiri (~> 1.8.2)
6
6
 
7
7
  GEM
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 `KeyError` exception, should the date or currency be unavailable.
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.fetch_data_and_save_to_disk
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`. Fonts: [here](http://man7.org/linux/man-pages/man5/crontab.5.html) and [here](http://www.adminschoice.com/crontab-quick-reference)
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)
@@ -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
@@ -1,4 +1,5 @@
1
1
  require 'fafx/version'
2
+ require 'fafx/core'
2
3
  require 'fafx/data_fetcher'
3
- require 'fafx/er'
4
+ require 'fafx/date_error'
4
5
  require 'fafx/exchange_rate'
@@ -1,6 +1,6 @@
1
1
  require 'yaml'
2
2
 
3
- class ER
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 KeyError, 'Date not available' unless @dates.include?(date)
14
- raise KeyError, "#{curr} not found" unless @currencies.include?(curr)
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.fetch_data_and_save_to_disk unless File.exist?(rates)
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
@@ -1,33 +1,40 @@
1
1
  module Fafx
2
2
  module ExchangeRate
3
3
  def at(date, base, other)
4
- ex_rates = ER.new
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
- ER.new.currencies
18
+ Core.new.currencies
12
19
  end
13
20
 
14
21
  def dates_available
15
- ER.new.dates
22
+ Core.new.dates
16
23
  end
17
24
 
18
25
  def most_recent
19
- ex_rates = ER.new
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 fetch_data_and_save_to_disk
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
- :fetch_data_and_save_to_disk
38
+ :update_data
32
39
  end
33
40
  end
@@ -1,3 +1,3 @@
1
1
  module Fafx
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
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.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: 2018-09-12 00:00:00.000000000 Z
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/er.rb
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