dw-currency-converter 0.0.0
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 +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/.semver +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +79 -0
- data/LICENSE.txt +20 -0
- data/README.org +96 -0
- data/Rakefile +53 -0
- data/dw-currency-converter.gemspec +71 -0
- data/lib/dw-currency-converter.rb +71 -0
- data/spec/money_spec.rb +65 -0
- data/spec/spec_helper.rb +23 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d4d4a4ab4d553ef7f457dcc80f3e9cf8dbc7f20e
|
4
|
+
data.tar.gz: 8bee05eb9e939928cf76e3ffaac787a8247b249a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ccc71c1f3fee718d04f8bb27f4c52ee21326530fccc80418db7766aab933383b65793dcc1646c321eac88f70ad333f3e49dadaf8ecc4a669aafa33d3f742d181
|
7
|
+
data.tar.gz: b716045ab0c69fc4f1696797522e77482c2b3b18c4ae1a5d1cebd257bd6ce9f32f628d06e726771cac8195a49c5a35efdff98c156472f25e8849246bb1b1d86c
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.semver
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "semver", "~> 1.0.1"
|
6
|
+
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "rspec", "~> 2.8.0"
|
11
|
+
gem "yard", "~> 0.7"
|
12
|
+
gem "rdoc", "~> 3.12"
|
13
|
+
gem "bundler", "~> 1.0"
|
14
|
+
gem "juwelier", "~> 2.1.0"
|
15
|
+
gem "simplecov", ">= 0"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.4.0)
|
5
|
+
builder (3.2.2)
|
6
|
+
descendants_tracker (0.0.4)
|
7
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
8
|
+
diff-lcs (1.1.3)
|
9
|
+
docile (1.1.5)
|
10
|
+
faraday (0.9.2)
|
11
|
+
multipart-post (>= 1.2, < 3)
|
12
|
+
git (1.3.0)
|
13
|
+
github_api (0.14.5)
|
14
|
+
addressable (~> 2.4.0)
|
15
|
+
descendants_tracker (~> 0.0.4)
|
16
|
+
faraday (~> 0.8, < 0.10)
|
17
|
+
hashie (>= 3.4)
|
18
|
+
oauth2 (~> 1.0)
|
19
|
+
hashie (3.4.6)
|
20
|
+
highline (1.7.8)
|
21
|
+
json (1.8.3)
|
22
|
+
juwelier (2.1.3)
|
23
|
+
builder
|
24
|
+
bundler (>= 1.13)
|
25
|
+
git (>= 1.2.5)
|
26
|
+
github_api
|
27
|
+
highline (>= 1.6.15)
|
28
|
+
nokogiri (>= 1.5.10)
|
29
|
+
rake
|
30
|
+
rdoc
|
31
|
+
semver
|
32
|
+
jwt (1.5.6)
|
33
|
+
mini_portile2 (2.1.0)
|
34
|
+
multi_json (1.12.1)
|
35
|
+
multi_xml (0.5.5)
|
36
|
+
multipart-post (2.0.0)
|
37
|
+
nokogiri (1.6.8.1)
|
38
|
+
mini_portile2 (~> 2.1.0)
|
39
|
+
oauth2 (1.2.0)
|
40
|
+
faraday (>= 0.8, < 0.10)
|
41
|
+
jwt (~> 1.0)
|
42
|
+
multi_json (~> 1.3)
|
43
|
+
multi_xml (~> 0.5)
|
44
|
+
rack (>= 1.2, < 3)
|
45
|
+
rack (2.0.1)
|
46
|
+
rake (11.3.0)
|
47
|
+
rdoc (3.12.2)
|
48
|
+
json (~> 1.4)
|
49
|
+
rspec (2.8.0)
|
50
|
+
rspec-core (~> 2.8.0)
|
51
|
+
rspec-expectations (~> 2.8.0)
|
52
|
+
rspec-mocks (~> 2.8.0)
|
53
|
+
rspec-core (2.8.0)
|
54
|
+
rspec-expectations (2.8.0)
|
55
|
+
diff-lcs (~> 1.1.2)
|
56
|
+
rspec-mocks (2.8.0)
|
57
|
+
semver (1.0.1)
|
58
|
+
simplecov (0.12.0)
|
59
|
+
docile (~> 1.1.0)
|
60
|
+
json (>= 1.8, < 3)
|
61
|
+
simplecov-html (~> 0.10.0)
|
62
|
+
simplecov-html (0.10.0)
|
63
|
+
thread_safe (0.3.5)
|
64
|
+
yard (0.9.5)
|
65
|
+
|
66
|
+
PLATFORMS
|
67
|
+
ruby
|
68
|
+
|
69
|
+
DEPENDENCIES
|
70
|
+
bundler (~> 1.0)
|
71
|
+
juwelier (~> 2.1.0)
|
72
|
+
rdoc (~> 3.12)
|
73
|
+
rspec (~> 2.8.0)
|
74
|
+
semver (~> 1.0.1)
|
75
|
+
simplecov
|
76
|
+
yard (~> 0.7)
|
77
|
+
|
78
|
+
BUNDLED WITH
|
79
|
+
1.13.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Fred Mitchell
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.org
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
* Ruby/Fullstack Task
|
2
|
+
This is a simple gem to do currency conversion. It was inspired
|
3
|
+
by a challenge from a particular firm, but might be useful
|
4
|
+
to you otherwise.
|
5
|
+
|
6
|
+
** Documentation
|
7
|
+
Please see the tests in [[./spec/money_spec.rb][RSpec Money Test]] as an example of usage.
|
8
|
+
|
9
|
+
** Canidate Challenge
|
10
|
+
*** Canidate Note
|
11
|
+
I added simplified exception handling for attempted
|
12
|
+
conversions that are not covered.
|
13
|
+
|
14
|
+
*** Requirements and Expectations
|
15
|
+
Hello dear candidate,
|
16
|
+
|
17
|
+
as part of the interview process to join the DaWanda Engineering Team,
|
18
|
+
we would ask you to complete a short homework task. We hope you will
|
19
|
+
enjoy it :)
|
20
|
+
|
21
|
+
We estimate the time needed to complete this task to be in the range of
|
22
|
+
a few hours. During evaluation, we focus mostly on:
|
23
|
+
|
24
|
+
- Structure of the code
|
25
|
+
- Proper testing
|
26
|
+
- Consistency of the code style
|
27
|
+
- Correctness of the solution
|
28
|
+
- Simplicity vs. over-engineering
|
29
|
+
|
30
|
+
Here is your task:
|
31
|
+
|
32
|
+
Write a Ruby gem to perform currency conversion and arithmetics with
|
33
|
+
different currencies (we know there are already gems for that, but for
|
34
|
+
the sake of the exercise implement your own ;) ). The expected features
|
35
|
+
and the usage of the gem should be something like this:
|
36
|
+
|
37
|
+
#+BEGIN_EXAMPLE
|
38
|
+
# Configure the currency rates with respect to a base currency (here EUR):
|
39
|
+
|
40
|
+
Money.conversion_rates('EUR', {
|
41
|
+
'USD' => 1.11,
|
42
|
+
'Bitcoin' => 0.0047
|
43
|
+
})
|
44
|
+
|
45
|
+
# Instantiate money objects:
|
46
|
+
|
47
|
+
fifty_eur = Money.new(50, 'EUR')
|
48
|
+
|
49
|
+
# Get amount and currency:
|
50
|
+
|
51
|
+
fifty_eur.amount # => 50
|
52
|
+
fifty_eur.currency # => "EUR"
|
53
|
+
fifty_eur.inspect # => "50.00 E0UR"
|
54
|
+
|
55
|
+
# Convert to a different currency (should return a Money
|
56
|
+
# instance, not a String):
|
57
|
+
|
58
|
+
fifty_eur.convert_to('USD') # => 55.50 USD
|
59
|
+
|
60
|
+
# Perform operations in different currencies:
|
61
|
+
|
62
|
+
twenty_dollars = Money.new(20, 'USD')
|
63
|
+
|
64
|
+
# Arithmetics:
|
65
|
+
|
66
|
+
fifty_eur + twenty_dollars # => 68.02 EUR
|
67
|
+
fifty_eur - twenty_dollars # => 31.98 EUR
|
68
|
+
fifty_eur / 2 # => 25 EUR
|
69
|
+
twenty_dollars * 3 # => 60 USD
|
70
|
+
|
71
|
+
# Comparisons (also in different currencies):
|
72
|
+
|
73
|
+
twenty_dollars == Money.new(20, 'USD') # => true
|
74
|
+
twenty_dollars == Money.new(30, 'USD') # => false
|
75
|
+
|
76
|
+
fifty_eur_in_usd = fifty_eur.convert_to('USD')
|
77
|
+
fifty_eur_in_usd == fifty_eur # => true
|
78
|
+
|
79
|
+
twenty_dollars > Money.new(5, 'USD') # => true
|
80
|
+
twenty_dollars < fifty_eur # => true
|
81
|
+
#+END_EXAMPLE
|
82
|
+
|
83
|
+
For the purpose of this exercise, when implementing equality, you can
|
84
|
+
consider two monetary amounts as equal if they agree up to the cents.
|
85
|
+
|
86
|
+
You might want to namespace your gem not to conflict with existing gems
|
87
|
+
with the same name.
|
88
|
+
|
89
|
+
Keep it simple, no need to support other features rather than these. The
|
90
|
+
clearer your code the better. But please write tests or documentation
|
91
|
+
whenever it makes sense. Think as if other people will have to use your
|
92
|
+
gem or contribute to it.
|
93
|
+
|
94
|
+
Please note that the actual numbers here are based on the conversion
|
95
|
+
rate at the time we wrote the task. With different rates you will get
|
96
|
+
different numbers.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
require 'semver'
|
14
|
+
|
15
|
+
def s_version
|
16
|
+
SemVer.find.format "%M.%m.%p%s"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'juwelier'
|
20
|
+
Juwelier::Tasks.new do |gem|
|
21
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
22
|
+
gem.name = "dw-currency-converter"
|
23
|
+
gem.homepage = "http://github.com/flajann2/dw-currency-converter"
|
24
|
+
gem.license = "MIT"
|
25
|
+
gem.summary = %Q{Simple Conversion between currencies using a base currency.}
|
26
|
+
gem.description = %Q{Convert between any two specified currencies.
|
27
|
+
This is not ready for prime-time usage yet, but
|
28
|
+
can be used for now in non-production code.}
|
29
|
+
gem.email = "fred.mitchell@gmx.de"
|
30
|
+
gem.authors = ["Fred Mitchell"]
|
31
|
+
gem.version = s_version
|
32
|
+
gem.required_ruby_version = '>= 2.3.1'
|
33
|
+
|
34
|
+
# dependencies defined in Gemfile
|
35
|
+
end
|
36
|
+
Juwelier::RubygemsDotOrgTasks.new
|
37
|
+
|
38
|
+
require 'rspec/core'
|
39
|
+
require 'rspec/core/rake_task'
|
40
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
41
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "Code coverage detail"
|
45
|
+
task :simplecov do
|
46
|
+
ENV['COVERAGE'] = "true"
|
47
|
+
Rake::Task['spec'].execute
|
48
|
+
end
|
49
|
+
|
50
|
+
task :default => :spec
|
51
|
+
|
52
|
+
require 'yard'
|
53
|
+
YARD::Rake::YardocTask.new
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Generated by juwelier
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: dw-currency-converter 0.0.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "dw-currency-converter".freeze
|
9
|
+
s.version = "0.0.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["Fred Mitchell".freeze]
|
14
|
+
s.date = "2016-11-09"
|
15
|
+
s.description = "Convert between any two specified currencies.\n This is not ready for prime-time usage yet, but\n can be used for now in non-production code.".freeze
|
16
|
+
s.email = "fred.mitchell@gmx.de".freeze
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.org"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
".semver",
|
25
|
+
"Gemfile",
|
26
|
+
"Gemfile.lock",
|
27
|
+
"LICENSE.txt",
|
28
|
+
"README.org",
|
29
|
+
"Rakefile",
|
30
|
+
"dw-currency-converter.gemspec",
|
31
|
+
"lib/dw-currency-converter.rb",
|
32
|
+
"spec/money_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/flajann2/dw-currency-converter".freeze
|
36
|
+
s.licenses = ["MIT".freeze]
|
37
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.3.1".freeze)
|
38
|
+
s.rubygems_version = "2.6.7".freeze
|
39
|
+
s.summary = "Simple Conversion between currencies using a base currency.".freeze
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 4
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<semver>.freeze, ["~> 1.0.1"])
|
46
|
+
s.add_development_dependency(%q<rspec>.freeze, ["~> 2.8.0"])
|
47
|
+
s.add_development_dependency(%q<yard>.freeze, ["~> 0.7"])
|
48
|
+
s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
49
|
+
s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
50
|
+
s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
|
51
|
+
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<semver>.freeze, ["~> 1.0.1"])
|
54
|
+
s.add_dependency(%q<rspec>.freeze, ["~> 2.8.0"])
|
55
|
+
s.add_dependency(%q<yard>.freeze, ["~> 0.7"])
|
56
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
57
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
58
|
+
s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
|
59
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<semver>.freeze, ["~> 1.0.1"])
|
63
|
+
s.add_dependency(%q<rspec>.freeze, ["~> 2.8.0"])
|
64
|
+
s.add_dependency(%q<yard>.freeze, ["~> 0.7"])
|
65
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
66
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
67
|
+
s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
|
68
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module DwCurrencyConv
|
4
|
+
class Money
|
5
|
+
attr :amount, :currency
|
6
|
+
|
7
|
+
def self.conversion_rates base, rate_list
|
8
|
+
@@base_currency = base.to_s
|
9
|
+
@@rate_list = rate_list.to_h
|
10
|
+
@@rate_list[base] = 1.0 # to simplify conversion logic
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize amount, currency
|
14
|
+
@amount = amount.to_f
|
15
|
+
@currency = currency.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def convert_to(currency)
|
19
|
+
begin
|
20
|
+
if currency == @@base_currency # converting to base currency
|
21
|
+
Money.new(self.amount * 1.0 / @@rate_list[self.currency], currency)
|
22
|
+
|
23
|
+
elsif self.currency == @@base_currency # converting from the base currency
|
24
|
+
Money.new(self.amount * @@rate_list[currency] / 1.0, currency)
|
25
|
+
|
26
|
+
else # converting between currencies -- first conver to base, then from base to target
|
27
|
+
convert_to(@@base_currency).convert_to(currency)
|
28
|
+
end
|
29
|
+
rescue => e
|
30
|
+
raise "Problem with converting #{self.currency} to #{currency}: #{e}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Add these two objects and yield a third.
|
35
|
+
def +(other_money)
|
36
|
+
Money.new(amount +
|
37
|
+
other_money.convert_to(currency).amount,
|
38
|
+
self.currency)
|
39
|
+
end
|
40
|
+
|
41
|
+
def -(other_money)
|
42
|
+
Money.new(self.amount -
|
43
|
+
other_money.convert_to(self.currency).amount,
|
44
|
+
self.currency)
|
45
|
+
end
|
46
|
+
|
47
|
+
def *(x)
|
48
|
+
Money.new(self.amount * x, self.currency)
|
49
|
+
end
|
50
|
+
|
51
|
+
def /(x)
|
52
|
+
Money.new(self.amount / x, self.currency)
|
53
|
+
end
|
54
|
+
|
55
|
+
def >(other_money)
|
56
|
+
self.amount > other_money.convert_to(self.currency).amount
|
57
|
+
end
|
58
|
+
|
59
|
+
def <(other_money)
|
60
|
+
self.amount < other_money.convert_to(self.currency).amount
|
61
|
+
end
|
62
|
+
|
63
|
+
def ==(other_money)
|
64
|
+
amount.round(2) == other_money.convert_to(currency).amount.round(2)
|
65
|
+
end
|
66
|
+
|
67
|
+
def inspect
|
68
|
+
"%.2f #{currency}" % [amount.round(2)]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/spec/money_spec.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'spec_helper'
|
4
|
+
|
5
|
+
include DwCurrencyConv
|
6
|
+
|
7
|
+
describe Money do
|
8
|
+
before(:all) do
|
9
|
+
Money.conversion_rates 'EUR', {
|
10
|
+
'USD' => 1.11,
|
11
|
+
'Bitcoin' => 0.0047,
|
12
|
+
'PHP' => 53.768438,
|
13
|
+
'PLN' => 4.34457705
|
14
|
+
}
|
15
|
+
@a = Money.new 20, 'EUR'
|
16
|
+
@b = Money.new 40, 'USD'
|
17
|
+
@fifty_eur = Money.new 50, 'EUR'
|
18
|
+
@twenty_dollars = Money.new 20, 'USD'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can add two currencies" do
|
22
|
+
a_plus_b = @a + @b
|
23
|
+
expect(a_plus_b.inspect).to eq("56.04 EUR")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can convert between non-base currencies" do
|
27
|
+
from = Money.new 2000, 'PHP'
|
28
|
+
to = from.convert_to 'USD'
|
29
|
+
expect(to.amount.round(2)).to eq(41.29)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "get amount and currency" do
|
33
|
+
expect(@fifty_eur.amount).to eq(50)
|
34
|
+
expect(@fifty_eur.currency).to eq('EUR')
|
35
|
+
expect(@fifty_eur.inspect).to eq('50.00 EUR')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "convert to a different currency" do
|
39
|
+
expect(@fifty_eur.convert_to('USD').inspect).to eq('55.50 USD')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "does arithemetics" do
|
43
|
+
expect((@fifty_eur + @twenty_dollars).inspect).to eq('68.02 EUR')
|
44
|
+
expect((@fifty_eur - @twenty_dollars).inspect).to eq('31.98 EUR')
|
45
|
+
expect((@fifty_eur / 2).inspect).to eq('25.00 EUR')
|
46
|
+
expect((@twenty_dollars * 3).inspect).to eq('60.00 USD')
|
47
|
+
end
|
48
|
+
|
49
|
+
it "does comparasions" do
|
50
|
+
expect(@twenty_dollars == Money.new(20, 'USD')).to be_truthy
|
51
|
+
expect(@twenty_dollars == Money.new(30, 'USD')).to be_falsey
|
52
|
+
|
53
|
+
fifty_eur_in_usd = @fifty_eur.convert_to('USD')
|
54
|
+
|
55
|
+
expect(fifty_eur_in_usd == @fifty_eur).to be_truthy
|
56
|
+
expect(@twenty_dollars > Money.new(5, 'USD')).to be_truthy
|
57
|
+
expect(@twenty_dollars < @fifty_eur).to be_truthy
|
58
|
+
end
|
59
|
+
|
60
|
+
it "throws an exception if currency is not recognized" do
|
61
|
+
expect {
|
62
|
+
@twenty_dollars.convert_to('XXX')
|
63
|
+
}.to raise_error /Problem with converting EUR to XXX/
|
64
|
+
end
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'dw-currency-converter'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.expect_with :rspec do |expectations|
|
7
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
8
|
+
end
|
9
|
+
|
10
|
+
config.mock_with :rspec do |mocks|
|
11
|
+
mocks.verify_partial_doubles = true
|
12
|
+
end
|
13
|
+
|
14
|
+
config.warnings = true
|
15
|
+
|
16
|
+
if config.files_to_run.one?
|
17
|
+
config.default_formatter = 'doc'
|
18
|
+
end
|
19
|
+
|
20
|
+
config.profile_examples = 10
|
21
|
+
config.order = :random
|
22
|
+
Kernel.srand config.seed
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dw-currency-converter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fred Mitchell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: semver
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.8.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.8.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: juwelier
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.1.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.1.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: |-
|
112
|
+
Convert between any two specified currencies.
|
113
|
+
This is not ready for prime-time usage yet, but
|
114
|
+
can be used for now in non-production code.
|
115
|
+
email: fred.mitchell@gmx.de
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files:
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.org
|
121
|
+
files:
|
122
|
+
- ".document"
|
123
|
+
- ".rspec"
|
124
|
+
- ".semver"
|
125
|
+
- Gemfile
|
126
|
+
- Gemfile.lock
|
127
|
+
- LICENSE.txt
|
128
|
+
- README.org
|
129
|
+
- Rakefile
|
130
|
+
- dw-currency-converter.gemspec
|
131
|
+
- lib/dw-currency-converter.rb
|
132
|
+
- spec/money_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
homepage: http://github.com/flajann2/dw-currency-converter
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 2.3.1
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.6.7
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Simple Conversion between currencies using a base currency.
|
158
|
+
test_files: []
|