moneyc 1.0.0 → 1.0.1
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/Gemfile +1 -1
- data/Gemfile.lock +5 -2
- data/README.md +2 -2
- data/Rakefile +2 -2
- data/lib/moneyc.rb +8 -10
- data/lib/moneyc/converter.rb +19 -17
- data/lib/moneyc/fixer_http_client.rb +6 -6
- data/lib/moneyc/version.rb +1 -1
- data/moneyc.gemspec +9 -9
- data/spec/lib/money/converter_spec.rb +6 -6
- data/spec/lib/money/fixer_http_client_spec.rb +6 -6
- data/tasks/debug.rake +2 -2
- metadata +7 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 562752007bca3c6d2449c6cd2d8b7b5b09c28630
|
|
4
|
+
data.tar.gz: 017fb81d13021581301b026b4aec1c28be38730e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9589e57c0451c68fe370e1dd6e559f45c0116cbf6569d38c8a1e4a4a8ef73f5753204d18d54ca986f3d6f3475733b2d866ee9c2fc6f89067be1aa82a7704edf6
|
|
7
|
+
data.tar.gz: 62b28904363442879eec38589ff2df838e988e53878f29bbed00049be366022a00528238f90a7efa1e6783bb91ed2b204f881a72d730247b9e2a64139bff575a
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
moneyc (1.0.
|
|
5
|
-
activesupport (~> 4.
|
|
4
|
+
moneyc (1.0.1)
|
|
5
|
+
activesupport (~> 4.2)
|
|
6
6
|
rake (~> 10.4, >= 10.4)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
@@ -63,3 +63,6 @@ DEPENDENCIES
|
|
|
63
63
|
pry (~> 0.10)
|
|
64
64
|
rspec (~> 3.1)
|
|
65
65
|
timecop
|
|
66
|
+
|
|
67
|
+
BUNDLED WITH
|
|
68
|
+
1.10.6
|
data/README.md
CHANGED
|
@@ -32,11 +32,11 @@ gem install moneyc
|
|
|
32
32
|
require 'moneyc'
|
|
33
33
|
|
|
34
34
|
# Convert 7.55 EUR to USD
|
|
35
|
-
Moneyc::Converter.new(
|
|
35
|
+
Moneyc::Converter.new(from: 'EUR', to: 'USD').convert(7.55)
|
|
36
36
|
# => Float
|
|
37
37
|
|
|
38
38
|
# Convert with specific date 7.55 EUR to USD
|
|
39
|
-
Moneyc::Converter.new(
|
|
39
|
+
Moneyc::Converter.new(from: 'EUR', to: 'USD', at: Time.now).convert(7.55)
|
|
40
40
|
# => Float
|
|
41
41
|
|
|
42
42
|
# Get today rate (EUR to USD)
|
data/Rakefile
CHANGED
data/lib/moneyc.rb
CHANGED
|
@@ -4,14 +4,12 @@ require 'json'
|
|
|
4
4
|
require 'active_support/all'
|
|
5
5
|
|
|
6
6
|
module Moneyc
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
:SEK, :SGD, :THB, :TRY, :USD,
|
|
13
|
-
:ZAR, :EUR ]
|
|
7
|
+
AVAILABLE_CURRENCY = [:AUD, :BGN, :BRL, :CAD, :CHF,
|
|
8
|
+
:CNY, :CZK, :DKK, :GBP, :HKD, :HRK, :HUF, :IDR,
|
|
9
|
+
:ILS, :INR, :JPY, :KRW, :MXN, :MYR, :NOK, :NZD,
|
|
10
|
+
:PHP, :PLN, :RON, :RUB, :SEK, :SGD, :THB, :TRY,
|
|
11
|
+
:USD, :ZAR, :EUR]
|
|
14
12
|
|
|
15
|
-
autoload :FixerHTTPClient,
|
|
16
|
-
autoload :Converter,
|
|
17
|
-
end
|
|
13
|
+
autoload :FixerHTTPClient, 'moneyc/fixer_http_client'
|
|
14
|
+
autoload :Converter, 'moneyc/converter'
|
|
15
|
+
end
|
data/lib/moneyc/converter.rb
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
module Moneyc
|
|
2
2
|
class Converter
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
@
|
|
6
|
-
@
|
|
7
|
-
@target_currency = options[:to].present? ? options[:to] : @reference_currency
|
|
8
|
-
@conversion_date = options[:at].present? ? options[:at] : Time.now
|
|
3
|
+
def initialize(from:, to: nil, at: nil)
|
|
4
|
+
@reference_currency = from
|
|
5
|
+
@target_currency = to.presence || @reference_currency
|
|
6
|
+
@conversion_date = at.presence || Time.now
|
|
9
7
|
end
|
|
10
8
|
|
|
11
9
|
def rate
|
|
12
|
-
reference_and_target_is_same?
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def convert
|
|
16
|
-
if @money_in_reference_currency.present?
|
|
17
|
-
@money_in_reference_currency.to_f * rate
|
|
10
|
+
if reference_and_target_is_same?
|
|
11
|
+
1
|
|
18
12
|
else
|
|
19
|
-
|
|
13
|
+
retrieve_taget_currency_rate
|
|
20
14
|
end
|
|
21
15
|
end
|
|
22
16
|
|
|
17
|
+
def convert(total_in_reference_currency)
|
|
18
|
+
total_in_reference_currency.to_f * rate
|
|
19
|
+
end
|
|
20
|
+
|
|
23
21
|
private
|
|
24
22
|
|
|
25
23
|
def reference_and_target_is_same?
|
|
@@ -27,20 +25,24 @@ module Moneyc
|
|
|
27
25
|
end
|
|
28
26
|
|
|
29
27
|
def retrieve_taget_currency_rate
|
|
30
|
-
if http_response.present? &&
|
|
28
|
+
if http_response.present? &&
|
|
29
|
+
http_response[@target_currency.to_sym].present?
|
|
30
|
+
|
|
31
31
|
http_response[@target_currency.to_sym]
|
|
32
32
|
else
|
|
33
|
-
|
|
33
|
+
fail ArgumentError, argument_error_message
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
def argument_error_message
|
|
38
|
+
"#@target_currency or #@reference_currency is not available currency"
|
|
39
|
+
end
|
|
40
|
+
|
|
37
41
|
def http_response
|
|
38
42
|
FixerHTTPClient.new(
|
|
39
43
|
conversion_date: @conversion_date,
|
|
40
44
|
reference_currency: @reference_currency
|
|
41
45
|
).fetch_currency_rate
|
|
42
46
|
end
|
|
43
|
-
|
|
44
|
-
class ConverterError < StandardError; end
|
|
45
47
|
end
|
|
46
48
|
end
|
|
@@ -6,27 +6,27 @@ module Moneyc
|
|
|
6
6
|
def initialize(conversion_date:, reference_currency:)
|
|
7
7
|
@conversion_date = conversion_date.strftime('%Y-%m-%d')
|
|
8
8
|
@reference_currency = reference_currency.to_s
|
|
9
|
+
@uri = construct_uri
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
def fetch_currency_rate
|
|
12
|
-
construct_uri
|
|
13
13
|
retrieve_rate
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
private
|
|
17
17
|
|
|
18
|
-
attr_reader :uri
|
|
19
|
-
|
|
20
18
|
def construct_uri
|
|
21
|
-
|
|
19
|
+
URI("#{ API_PROTOCOL }#{ BASE_API_URL }/#@conversion_date/?base=#@reference_currency")
|
|
22
20
|
end
|
|
23
21
|
|
|
24
22
|
def retrieve_rate
|
|
25
|
-
JSON.parse(call_api, { symbolize_names: true})
|
|
23
|
+
JSON.parse(call_api, { symbolize_names: true }).fetch(:rates)
|
|
24
|
+
rescue KeyError
|
|
25
|
+
fail ArgumentError, 'target currency is not available'
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def call_api
|
|
29
|
-
http_client.get(uri)
|
|
29
|
+
http_client.get(@uri)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def http_client
|
data/lib/moneyc/version.rb
CHANGED
data/moneyc.gemspec
CHANGED
|
@@ -3,14 +3,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
|
3
3
|
require 'moneyc/version'
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |gem|
|
|
6
|
-
gem.name =
|
|
6
|
+
gem.name = 'moneyc'
|
|
7
7
|
gem.version = Moneyc::VERSION
|
|
8
|
-
gem.authors =
|
|
9
|
-
gem.email =
|
|
10
|
-
gem.description =
|
|
11
|
-
gem.summary =
|
|
12
|
-
gem.homepage =
|
|
13
|
-
gem.license =
|
|
8
|
+
gem.authors = %w(Bryan FRIMIN)
|
|
9
|
+
gem.email = %w(bfrimin@student.42.fr)
|
|
10
|
+
gem.description = 'Convert your currency with simple lib'
|
|
11
|
+
gem.summary = 'Convert et retrive rate of your currency with simple lib'
|
|
12
|
+
gem.homepage = 'https://github.com/gearnode/moneyc'
|
|
13
|
+
gem.license = 'MIT'
|
|
14
14
|
|
|
15
15
|
gem.required_ruby_version = '>= 2.2'
|
|
16
16
|
gem.required_rubygems_version = '>= 1.8.11'
|
|
@@ -18,12 +18,12 @@ Gem::Specification.new do |gem|
|
|
|
18
18
|
gem.files = `git ls-files`.split($/)
|
|
19
19
|
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
20
20
|
gem.test_files = gem.files.grep(%r{^(spec)/})
|
|
21
|
-
gem.require_paths = [
|
|
21
|
+
gem.require_paths = ['lib']
|
|
22
22
|
|
|
23
23
|
gem.add_runtime_dependency 'rake', '~> 10.4', '>= 10.4'
|
|
24
24
|
|
|
25
25
|
gem.add_development_dependency 'bundler', '~> 1.7'
|
|
26
26
|
gem.add_development_dependency 'rspec', '~> 3.1'
|
|
27
27
|
gem.add_development_dependency 'pry', '~> 0.10'
|
|
28
|
-
gem.add_dependency 'activesupport', '~> 4.
|
|
28
|
+
gem.add_dependency 'activesupport', '~> 4.2'
|
|
29
29
|
end
|
|
@@ -4,7 +4,7 @@ describe Moneyc::Converter do
|
|
|
4
4
|
|
|
5
5
|
describe '#rate' do
|
|
6
6
|
subject{ described_class.new(from: reference_currency, to: target_currency, at: date).rate }
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
let(:date){ Time.new('2015', '8', '20') }
|
|
9
9
|
|
|
10
10
|
context 'when reference and target currency is same' do
|
|
@@ -57,13 +57,13 @@ describe Moneyc::Converter do
|
|
|
57
57
|
let(:target_currency){ 'ISNOTACURRENCY' }
|
|
58
58
|
|
|
59
59
|
it 'raises a error' do
|
|
60
|
-
expect{ subject }.to raise_error(
|
|
60
|
+
expect{ subject }.to raise_error(ArgumentError)
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
describe '#convert' do
|
|
66
|
-
subject{ described_class.new(
|
|
66
|
+
subject{ described_class.new(from: reference_currency, to: target_currency, at: date).convert(7) }
|
|
67
67
|
|
|
68
68
|
let(:date){ Time.new('2015', '8', '20') }
|
|
69
69
|
|
|
@@ -116,9 +116,9 @@ describe Moneyc::Converter do
|
|
|
116
116
|
let(:reference_currency){ 'ISNOTACURRENCY' }
|
|
117
117
|
let(:target_currency){ 'USD' }
|
|
118
118
|
|
|
119
|
-
it '
|
|
120
|
-
expect{ subject }.to raise_error(
|
|
119
|
+
it 'returns nil' do
|
|
120
|
+
expect{ subject }.to raise_error(ArgumentError)
|
|
121
121
|
end
|
|
122
122
|
end
|
|
123
123
|
end
|
|
124
|
-
end
|
|
124
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Moneyc::FixerHTTPClient do
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
describe '#fetch_currency_rate' do
|
|
6
6
|
subject{ described_class.new(conversion_date: conversion_date, reference_currency: reference_currency).fetch_currency_rate }
|
|
7
7
|
|
|
@@ -14,7 +14,7 @@ describe Moneyc::FixerHTTPClient do
|
|
|
14
14
|
expect(subject).to be_a(Hash)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
it '
|
|
17
|
+
it 'returns hash with eur' do
|
|
18
18
|
expect(subject[:EUR]).not_to be_nil
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -22,9 +22,9 @@ describe Moneyc::FixerHTTPClient do
|
|
|
22
22
|
context 'when reference_currency is not available' do
|
|
23
23
|
let(:reference_currency){ :WDFGYUJI }
|
|
24
24
|
|
|
25
|
-
it '
|
|
26
|
-
expect
|
|
27
|
-
end
|
|
25
|
+
it 'raises error' do
|
|
26
|
+
expect{ subject }.to raise_error(ArgumentError)
|
|
27
|
+
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
|
-
end
|
|
30
|
+
end
|
data/tasks/debug.rake
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: moneyc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
- Bryan
|
|
7
|
+
- Bryan
|
|
8
|
+
- FRIMIN
|
|
8
9
|
autorequire:
|
|
9
10
|
bindir: bin
|
|
10
11
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
12
|
+
date: 2015-12-31 00:00:00.000000000 Z
|
|
12
13
|
dependencies:
|
|
13
14
|
- !ruby/object:Gem::Dependency
|
|
14
15
|
name: rake
|
|
@@ -78,14 +79,14 @@ dependencies:
|
|
|
78
79
|
requirements:
|
|
79
80
|
- - "~>"
|
|
80
81
|
- !ruby/object:Gem::Version
|
|
81
|
-
version: '4.
|
|
82
|
+
version: '4.2'
|
|
82
83
|
type: :runtime
|
|
83
84
|
prerelease: false
|
|
84
85
|
version_requirements: !ruby/object:Gem::Requirement
|
|
85
86
|
requirements:
|
|
86
87
|
- - "~>"
|
|
87
88
|
- !ruby/object:Gem::Version
|
|
88
|
-
version: '4.
|
|
89
|
+
version: '4.2'
|
|
89
90
|
description: Convert your currency with simple lib
|
|
90
91
|
email:
|
|
91
92
|
- bfrimin@student.42.fr
|
|
@@ -129,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
129
130
|
version: 1.8.11
|
|
130
131
|
requirements: []
|
|
131
132
|
rubyforge_project:
|
|
132
|
-
rubygems_version: 2.4.
|
|
133
|
+
rubygems_version: 2.4.8
|
|
133
134
|
signing_key:
|
|
134
135
|
specification_version: 4
|
|
135
136
|
summary: Convert et retrive rate of your currency with simple lib
|