currency_converter_gem_nichohelmut 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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/currency_converter_gem_nichohelmut/version.rb +1 -1
- data/lib/currency_converter_gem_nichohelmut.rb +34 -53
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7564c8580075474ceee5d3b222d936e7cc0d2cc9
|
4
|
+
data.tar.gz: 3c224227563d78b9976591208e0dd2692ca2f330
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d613365f555be31b16b2d7b6b870efdb19a30afc2b629838f3c774b993af9206911b69f8c698293133d2f2c35a7c9e341fefd384342850388603728fba15a1c
|
7
|
+
data.tar.gz: 88f7b80dfa51fdb6e44289b056fd20c2a8451ea88c4c80b392c89cb1f172ec43459345882ed0602add7bd5c5cc1afd99b30d06d6ea2f236104714879f56624eb
|
data/Gemfile.lock
CHANGED
@@ -1,86 +1,67 @@
|
|
1
1
|
require "currency_converter_gem_nichohelmut/version"
|
2
2
|
|
3
3
|
module CurrencyConverterGemNichohelmut
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@amount = amount
|
9
|
-
@from_curr = from_curr
|
10
|
-
end
|
11
|
-
|
12
|
-
def amount
|
13
|
-
@amount
|
14
|
-
end
|
15
|
-
|
16
|
-
def from_curr
|
17
|
-
@from_curr
|
18
|
-
end
|
4
|
+
def initialize(amount, curr)
|
5
|
+
@amount = amount
|
6
|
+
@curr = curr
|
7
|
+
end
|
19
8
|
|
20
|
-
|
21
|
-
|
22
|
-
|
9
|
+
def self.conversion_rates(fx = {})
|
10
|
+
{'EUR'=>{'USD'=>1.2, 'Bitcoin'=>0.0047},
|
11
|
+
'USD'=>{'EUR'=>0.8, 'Bitcoin'=>0.0097},
|
12
|
+
'Bitcoin'=>{'USD'=>1.11, 'EUR'=>0.0047}}
|
13
|
+
end
|
23
14
|
|
15
|
+
def amount
|
16
|
+
@amount
|
17
|
+
end
|
24
18
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
return {'EUR'=>{'USD'=>1.23, 'Bitcoin'=>0.00016},
|
29
|
-
'USD'=>{'EUR'=>0.81, 'Bitcoin'=>0.00013},
|
30
|
-
'Bitcoin'=>{'USD'=>7468.23, 'EUR'=>6557.93}}
|
19
|
+
def curr
|
20
|
+
@curr
|
21
|
+
end
|
31
22
|
|
23
|
+
def inspect
|
24
|
+
'%.2f' % @amount.to_s + " " + @curr
|
25
|
+
end
|
32
26
|
|
27
|
+
def convert_to(to_curr)
|
28
|
+
if to_curr != self.curr
|
29
|
+
@rate = Money.conversion_rates[self.curr][to_curr]
|
30
|
+
Money.new(@amount * @rate, to_curr)
|
31
|
+
else
|
32
|
+
Money.new(@amount, curr)
|
33
33
|
end
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
if to_curr != self.from_curr
|
37
|
-
@rate = Money.conversion_rates[self.from_curr]["#{to_curr}"]
|
38
|
-
@converted_amount = @amount * @rate
|
39
|
-
Money.new(@converted_amount, to_curr)
|
40
|
-
else
|
41
|
-
Money.new(@amount, from_curr)
|
42
|
-
end
|
43
|
-
end
|
36
|
+
# --------------------------------------
|
44
37
|
|
45
38
|
def +(other)
|
46
|
-
|
47
|
-
result = self.amount + other.convert_to(curr).amount
|
48
|
-
return Money.new(result, curr)
|
39
|
+
Money.new(self.amount + other.convert_to(self.curr).amount, self.curr)
|
49
40
|
end
|
50
41
|
|
51
42
|
def -(other)
|
52
|
-
|
53
|
-
result = self.amount - other.convert_to(curr).amount
|
54
|
-
return Money.new(result, curr)
|
43
|
+
Money.new(self.amount - other.convert_to(self.curr).amount, self.curr)
|
55
44
|
end
|
56
45
|
|
57
46
|
def *(other)
|
58
|
-
|
59
|
-
Money.new(result, self.from_curr)
|
47
|
+
Money.new(self.amount * other, self.curr)
|
60
48
|
end
|
61
49
|
|
62
50
|
def /(other)
|
63
|
-
|
64
|
-
Money.new(result, self.from_curr)
|
51
|
+
Money.new(self.amount / other, self.curr)
|
65
52
|
end
|
66
53
|
|
67
|
-
|
68
|
-
|
69
|
-
result = (self.amount == other.convert_to(curr).amount)
|
54
|
+
def ==(other)
|
55
|
+
self.amount == other.convert_to(self.curr).amount
|
70
56
|
end
|
71
57
|
|
72
58
|
def >(other)
|
73
|
-
|
74
|
-
self.amount > other.convert_to(curr).amount
|
59
|
+
self.amount > other.convert_to(self.curr).amount
|
75
60
|
end
|
76
61
|
|
77
62
|
def <(other)
|
78
|
-
|
79
|
-
self.amount < other.convert_to(curr).amount
|
63
|
+
self.amount < other.convert_to(self.curr).amount
|
80
64
|
end
|
81
65
|
end
|
82
66
|
|
83
|
-
twenty_dollars = Money.new(20, "USD")
|
84
|
-
fifty_euro = Money.new(50, "EUR")
|
85
|
-
|
86
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: currency_converter_gem_nichohelmut
|
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
|
- Nicholas Utikal
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03
|
11
|
+
date: 2018-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|