dawanda_converter 0.1.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/lib/dawanda_converter.rb +6 -0
- data/lib/dawanda_converter/money.rb +99 -0
- data/lib/dawanda_converter/version.rb +3 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9ee916b19dcff4c8e9a17d30352534ebcbbaa480
|
4
|
+
data.tar.gz: c27aae9b4a377cb3389160c527bf020ca2a06267
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15f8b27d64190794d8263e909995b7d46873c688df034d8792f519af9fca4ee2d8e1f83e0bf306d37bc53a819c6033c551167c2b75fff2c2a0966f93896ead88
|
7
|
+
data.tar.gz: 68858cf44b0326f91babcf3bfada496fc73890261753aa399cd790514bb69141d7b21d3b9332c6914ec68f49ec684034e1f453f4af70afbcff8aa8e5a805643c
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module DawandaConverter
|
2
|
+
class Money
|
3
|
+
@@conversions = Hash.new #Declared as a Class variable so all objects (Money) created have the same conversion rates available
|
4
|
+
|
5
|
+
def initialize(amount, currency)
|
6
|
+
@amount = ( amount || 0 ) #if nil it just assigns ZERO
|
7
|
+
@currency = currency
|
8
|
+
end
|
9
|
+
#--------------------ACCESSORS---------------------------------------------#
|
10
|
+
def amount
|
11
|
+
@amount
|
12
|
+
end
|
13
|
+
|
14
|
+
def currency
|
15
|
+
@currency
|
16
|
+
end
|
17
|
+
|
18
|
+
def currency=(currency)
|
19
|
+
@currency = currency
|
20
|
+
end
|
21
|
+
|
22
|
+
def amount=(amount)
|
23
|
+
@amount = (amount || 0 )
|
24
|
+
end
|
25
|
+
|
26
|
+
def inspect
|
27
|
+
"#{@amount} #{@currency}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def conversions
|
31
|
+
@@conversions
|
32
|
+
end
|
33
|
+
#--------------------------------------------------------------------------#
|
34
|
+
|
35
|
+
def self.conversion_rates(currency="", hash={})
|
36
|
+
@@conversions[currency] = hash unless currency.empty? || hash.empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
def convert_to(currency)
|
40
|
+
unless @@conversions.empty? || @@conversions[self.currency].nil?
|
41
|
+
self.amount = @@conversions[self.currency][currency].to_f * self.amount
|
42
|
+
self.currency = currency
|
43
|
+
else
|
44
|
+
puts "You must initialize conversion rates first."
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
#-------------OPERATORS SECTION-------------------------------------------#
|
49
|
+
|
50
|
+
def +(y)
|
51
|
+
if self.currency != y.currency
|
52
|
+
y.convert_to(self.currency)
|
53
|
+
end
|
54
|
+
|
55
|
+
return "#{self.amount + y.amount} #{self.currency}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def -(y)
|
59
|
+
if self.currency != y.currency
|
60
|
+
y.convert_to(self.currency)
|
61
|
+
end
|
62
|
+
|
63
|
+
return "#{self.amount - y.amount} #{self.currency}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def /(y)
|
67
|
+
return "You cannot devide by ZERO!." if y == 0
|
68
|
+
return "#{self.amount / y} #{self.currency}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def *(y)
|
72
|
+
return "#{self.amount * y} #{self.currency}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def ==(y)
|
76
|
+
return true if self.amount == y.amount && self.currency == y.currency
|
77
|
+
return false
|
78
|
+
end
|
79
|
+
|
80
|
+
def <(y)
|
81
|
+
if self.currency != y.currency
|
82
|
+
y.convert_to(self.currency)
|
83
|
+
end
|
84
|
+
return true if self.amount < y.amount
|
85
|
+
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
|
89
|
+
def >(y)
|
90
|
+
if self.currency != y.currency
|
91
|
+
y.convert_to(self.currency)
|
92
|
+
end
|
93
|
+
return true if self.amount > y.amount
|
94
|
+
|
95
|
+
return false
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dawanda_converter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Freddy Gonzalez
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Basically this is an exercise made for DaWanda Company.
|
70
|
+
email:
|
71
|
+
- freddy.gonzalezp.17@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- lib/dawanda_converter.rb
|
77
|
+
- lib/dawanda_converter/money.rb
|
78
|
+
- lib/dawanda_converter/version.rb
|
79
|
+
homepage: http://rubygems.org/gems/dawanda_converter
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.5.1
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Example gem to make money conversion and arithmetics operations.
|
103
|
+
test_files: []
|