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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0f9cd75f72cda30bce1922b83396ed4a33a7e9a
4
- data.tar.gz: 6b26117ba8625b7a2ed823163868b5e1f5d7a3ae
3
+ metadata.gz: 7564c8580075474ceee5d3b222d936e7cc0d2cc9
4
+ data.tar.gz: 3c224227563d78b9976591208e0dd2692ca2f330
5
5
  SHA512:
6
- metadata.gz: 86990eaada2926c706f2fcb6bc4d5ccdc4f7fca15209c9ac1b16e312e1743e7ef5bf88628827d2b934988b775a1a85ba58115bd2f6557a45c010ecf34e0a76f8
7
- data.tar.gz: e7f3fb56e98e927880c37b570a46a1db586277519b1fb6b474c4fc7b9a76cbd130fcba7b7ce6e46d148a906330caae14387c6293f8155fa6e45d0e83ac35e00d
6
+ metadata.gz: 3d613365f555be31b16b2d7b6b870efdb19a30afc2b629838f3c774b993af9206911b69f8c698293133d2f2c35a7c9e341fefd384342850388603728fba15a1c
7
+ data.tar.gz: 88f7b80dfa51fdb6e44289b056fd20c2a8451ea88c4c80b392c89cb1f172ec43459345882ed0602add7bd5c5cc1afd99b30d06d6ea2f236104714879f56624eb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- currency_converter_gem_nichohelmut (0.1.1)
4
+ currency_converter_gem_nichohelmut (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module CurrencyConverterGemNichohelmut
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,86 +1,67 @@
1
1
  require "currency_converter_gem_nichohelmut/version"
2
2
 
3
3
  module CurrencyConverterGemNichohelmut
4
- class Money
5
- attr_accessor :amount, :converted_amount
6
-
7
- def initialize(amount, from_curr)
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
- def inspect
21
- '%.2f' % @amount.to_s + " " + @from_curr
22
- end
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
- def self.conversion_rates(attr = {})
26
- # @conv_rates = {from_curr = {rates}} Use Hard Code for now
27
- # refactor to attr ={}
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
- def convert_to(to_curr)
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
- curr = self.from_curr
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
- curr = self.from_curr
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
- result = self.amount * other
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
- result = self.amount / other
64
- Money.new(result, self.from_curr)
51
+ Money.new(self.amount / other, self.curr)
65
52
  end
66
53
 
67
- def ==(other)
68
- curr = self.from_curr
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
- curr = self.from_curr
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
- curr = self.from_curr
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.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-30 00:00:00.000000000 Z
11
+ date: 2018-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler