moneytest 0.1.0 → 0.1.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/lib/arithmetic/arithmetic.rb +34 -0
- data/lib/configuration/configuration.rb +18 -0
- data/lib/convert/convert.rb +23 -0
- data/lib/error/handle_error.rb +6 -0
- data/lib/moneytest/version.rb +1 -1
- data/lib/moneytest.rb +59 -3
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df1a682fa99cabc370de120ec205adf1d7dc6b48
|
4
|
+
data.tar.gz: 22903f1352d6268f7a62d1707543b11ef13ba940
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f02cbdfeeca74cf7e3ef6d829ac8b2cceecd32e487243489e6dfd3be49a089ce9d78c6c19d7fcb7d7d43738b0f56ea713c4270325d93c51f1278e1956421c26e
|
7
|
+
data.tar.gz: 50ed39abe06f7acfb04ad586da861682754b94ec09ddf02130901577cb078f3ffb8fea84dc752aba8ed8df18df46fae06c4a9759d9b796936a8a7b44353fcbb1
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Arithmetic
|
2
|
+
|
3
|
+
def value_exist(value)
|
4
|
+
value.respond_to?(:to_i) ? value : value.amount
|
5
|
+
end
|
6
|
+
|
7
|
+
def + (value)
|
8
|
+
(@amount + value_exist(value))
|
9
|
+
end
|
10
|
+
|
11
|
+
def - (value)
|
12
|
+
(@amount - value_exist(value))
|
13
|
+
end
|
14
|
+
|
15
|
+
def * (value)
|
16
|
+
(@amount * value_exist(value))
|
17
|
+
end
|
18
|
+
|
19
|
+
def / (value)
|
20
|
+
(@amount / value_exist(value))
|
21
|
+
end
|
22
|
+
|
23
|
+
def > (value)
|
24
|
+
(@amount > value_exist(value))
|
25
|
+
end
|
26
|
+
|
27
|
+
def < (value)
|
28
|
+
(@amount < value_exist(value))
|
29
|
+
end
|
30
|
+
|
31
|
+
def == (value)
|
32
|
+
(@amount == value_exist(value))
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Money::Configuration
|
2
|
+
attr_accessor :default_currency, :conversions
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@default_currency = 'EUR'
|
6
|
+
@conversions = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
#configuración default
|
12
|
+
Money.configure do |cfg|
|
13
|
+
cfg.default_currency = "EUR"
|
14
|
+
cfg.conversions = {
|
15
|
+
'USD' => 1.11,
|
16
|
+
'Bitcoin' => 0.0047
|
17
|
+
}
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ConvertArit
|
2
|
+
|
3
|
+
class Convert
|
4
|
+
|
5
|
+
|
6
|
+
def initialize(currency)
|
7
|
+
@currency = currency
|
8
|
+
end
|
9
|
+
|
10
|
+
def convert_to(currency)
|
11
|
+
case @currency
|
12
|
+
when "EUR"
|
13
|
+
@amount * 1.11 unless @type == "EUR"
|
14
|
+
when "Bitcoin"
|
15
|
+
@amount * 0.0047 unless @type == "Bitcoin"
|
16
|
+
when "USD"
|
17
|
+
@amount * 1.11 unless @type == "USD"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/moneytest/version.rb
CHANGED
data/lib/moneytest.rb
CHANGED
@@ -1,5 +1,61 @@
|
|
1
|
-
|
1
|
+
class Money
|
2
|
+
attr_accessor :amount, :currency
|
3
|
+
|
4
|
+
#################### validación y configuración
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def configure
|
8
|
+
@@configuration ||= Configuration.new
|
9
|
+
yield(@@configuration)
|
10
|
+
end
|
11
|
+
|
12
|
+
def validate_currency(currency)
|
13
|
+
valid_currencies = @@configuration.conversions.keys #busca las keys del bloque
|
14
|
+
valid_currencies += [@@configuration.default_currency]
|
15
|
+
raise CurrencyError.new(currency) if ([currency] & valid_currencies).empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
######################################
|
20
|
+
|
21
|
+
def initialize(amount, currency = nil)
|
22
|
+
@@configuration ||= Configuration.new #aplico config
|
23
|
+
self.class.validate_currency(currency) #valido
|
24
|
+
@amount = amount
|
25
|
+
@currency = currency || @@configuration.default_currency #si no hay divisa, se agrega la default
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect #monto más divisa
|
29
|
+
{amount: @amount, currency: @currency }
|
30
|
+
end
|
31
|
+
|
32
|
+
def amount #monto
|
33
|
+
@amount
|
34
|
+
end
|
35
|
+
|
36
|
+
def currency #divisa
|
37
|
+
@currency
|
38
|
+
end
|
39
|
+
|
40
|
+
def convert(new_currency) #conversión
|
41
|
+
factor_to = new_currency == @@configuration.default_currency ? 1 : @@configuration.conversions[new_currency].to_f
|
42
|
+
factor_from = @currency == @@configuration.default_currency ? 1 : @@configuration.conversions[@currency].to_f
|
43
|
+
#si es la misma divisa o no
|
44
|
+
Money.new(@amount * factor_to / factor_from, new_currency) #nueva instancia / calculo
|
45
|
+
end
|
2
46
|
|
3
|
-
module Moneytest
|
4
|
-
# Your code goes here...
|
5
47
|
end
|
48
|
+
|
49
|
+
require_relative './configuration/configuration'
|
50
|
+
require_relative './error/handle_error'
|
51
|
+
|
52
|
+
# m1 = Money.new(100000, 'EUR')
|
53
|
+
# m2 = m1.convert('EUR')
|
54
|
+
# m3 = m1.convert('USD')
|
55
|
+
# m4 = m1.convert('Bitcoin')
|
56
|
+
# p m1.amount
|
57
|
+
# p m1.currency
|
58
|
+
# puts m1.inspect
|
59
|
+
# puts m2.inspect
|
60
|
+
# puts m3.inspect
|
61
|
+
# puts m4.inspect
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moneytest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- t00l
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,6 +69,10 @@ files:
|
|
69
69
|
- Rakefile
|
70
70
|
- bin/console
|
71
71
|
- bin/setup
|
72
|
+
- lib/arithmetic/arithmetic.rb
|
73
|
+
- lib/configuration/configuration.rb
|
74
|
+
- lib/convert/convert.rb
|
75
|
+
- lib/error/handle_error.rb
|
72
76
|
- lib/moneytest.rb
|
73
77
|
- lib/moneytest/version.rb
|
74
78
|
- moneytest.gemspec
|