currency_shushugah 1.0.1 → 2.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 +4 -4
- data/currency_shushugah.gemspec +3 -3
- data/lib/currency_shushugah/version.rb +1 -1
- data/lib/currency_shushugah.rb +70 -51
- metadata +6 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 025a361a07ad5469e9f3b19f285c1882d4d2b510
|
|
4
|
+
data.tar.gz: b0a579adf6581e8926192437148bf965d0e400a3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c3c2f0ecb2deb87d8a6abc4910b6d20bb04c38a45a0d0cd6e9d1b19db6ee22b527b8f01b34574460f4dc7c4d6008cb2c7230e30a13c850338e867b3a00b64be2
|
|
7
|
+
data.tar.gz: 76e6665f5ee08b7f089aae84707d4f5079fa7cb73ecd2595d435386df310d500457f4ec31c0b77bd68c751b3d682622a50438b96f16564653b622e59d0948a10
|
data/currency_shushugah.gemspec
CHANGED
|
@@ -6,10 +6,10 @@ require 'currency_shushugah/version'
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "currency_shushugah"
|
|
8
8
|
spec.version = CurrencyShushugah::VERSION
|
|
9
|
-
spec.authors = ["
|
|
9
|
+
spec.authors = ["Yonatan Miller"]
|
|
10
10
|
spec.email = ["brombacher1@gmail.com"]
|
|
11
11
|
|
|
12
|
-
spec.summary = "Converts currencies
|
|
12
|
+
spec.summary = "Converts currencies and accepts conversion rates"
|
|
13
13
|
spec.homepage = "https://github.com/shushugah/currency_shushugah"
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
|
17
17
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
18
18
|
spec.require_paths = ["lib"]
|
|
19
19
|
|
|
20
|
-
spec.add_development_dependency "bundler", "~> 1.
|
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
|
21
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
22
22
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
23
23
|
end
|
data/lib/currency_shushugah.rb
CHANGED
|
@@ -1,55 +1,74 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'currency_shushugah/version'
|
|
2
2
|
|
|
3
|
+
# Understands currency and quantity
|
|
3
4
|
class Money
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
5
|
+
include Comparable
|
|
6
|
+
|
|
7
|
+
attr_reader :quantity, :currency
|
|
8
|
+
protected :currency, :quantity
|
|
9
|
+
|
|
10
|
+
def self.conversion_rates(base_currency, hash_rates)
|
|
11
|
+
@rates = hash_rates.merge(base_currency => 1)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize(quantity, currency)
|
|
15
|
+
raise StandardError.new('Not supported currency') unless rates[currency]
|
|
16
|
+
@quantity = quantity
|
|
17
|
+
@currency = currency
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def <=>(other)
|
|
21
|
+
return unless other.class == self.class
|
|
22
|
+
quantity <=> other.convert_to(currency).quantity
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def inspect
|
|
26
|
+
"#{'%0.2f' % quantity} #{currency}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def convert_to(other_currency)
|
|
30
|
+
raise StandardError.new('InvalidCurrency') unless rates[other_currency]
|
|
31
|
+
return self if currency == other_currency
|
|
32
|
+
new_quantity = @quantity * rates[other_currency] / rates[currency]
|
|
33
|
+
new_money(new_quantity, other_currency)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def +(other)
|
|
37
|
+
new_money(quantity + other.convert_to(currency).quantity)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def -(other)
|
|
41
|
+
self + -other
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def -@
|
|
45
|
+
new_money(-quantity)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def coerce(other)
|
|
49
|
+
return self, other
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def *(scalar)
|
|
53
|
+
new_money(quantity * scalar)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def /(scalar)
|
|
57
|
+
raise StandardError.new 'InvalidDivision' if scalar.zero?
|
|
58
|
+
self * (1.0 / scalar)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def new_money(quantity, currency = @currency)
|
|
62
|
+
Money.send :new, quantity.round(2), currency
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def self.rates
|
|
66
|
+
Money.instance_variable_get(:@rates)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def rates
|
|
72
|
+
self.class.rates
|
|
54
73
|
end
|
|
55
74
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: currency_shushugah
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- Yonatan Miller
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-07-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '1.
|
|
19
|
+
version: '1.15'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '1.
|
|
26
|
+
version: '1.15'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -98,6 +98,5 @@ rubyforge_project:
|
|
|
98
98
|
rubygems_version: 2.5.1
|
|
99
99
|
signing_key:
|
|
100
100
|
specification_version: 4
|
|
101
|
-
summary: Converts currencies
|
|
102
|
-
from an API
|
|
101
|
+
summary: Converts currencies and accepts conversion rates
|
|
103
102
|
test_files: []
|