money_hdamico 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/money.rb +91 -0
  3. data/lib/money_hdamico.rb +5 -0
  4. metadata +86 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bad0b0df5fa737584adbce820518f5d4b77f03ca24dc6b5168808f2d0f3c6556
4
+ data.tar.gz: 8fa084b1e3da82724f4a6081107da5380c6e3f9800d1340a84b7bdf60657223a
5
+ SHA512:
6
+ metadata.gz: 85ac0e7cdd0c838b0dade7ab6db27bd458c95df98e13aeeef053776159c12dd589d6cddd2ab49bc02da670971fc76ec97664fb749053ed5763469fef95980adb
7
+ data.tar.gz: 942c7eb5bb278ea71d3848d512178a5327c2f9ed884492afc6a2cf5211709cc558369e35e1d70e33722e7d59baa138856f86bf4971fad9074c75283a9ca16ccb
data/lib/money.rb ADDED
@@ -0,0 +1,91 @@
1
+ # lib/money.rb
2
+ require "money_hdamico"
3
+
4
+ class Money
5
+
6
+ attr_accessor :currency, :amount, :conversions
7
+
8
+ def initialize(amount = 0, currency = 'EUR')
9
+ @currency = currency
10
+ @amount = amount
11
+ @conversions = {
12
+ 'USD' => 1.11,
13
+ 'Bitcoin' => 0.0047
14
+ }
15
+ end
16
+
17
+ def convert_to(currency)
18
+ return raise 'Incorrect currency' unless self.currency != currency || @conversions.include?(currency)
19
+
20
+ self.amount = (@conversions[currency] * amount).round(2)
21
+ self.currency = currency
22
+ self
23
+ end
24
+
25
+ def -(other)
26
+ if other.is_a?(MoneyHdamico)
27
+ other.convert_to(currency) if other.currency != currency
28
+ MoneyHdamico.new(amount - other.amount, currency)
29
+ elsif other.is_a?(Numeric)
30
+ MoneyHdamico.new(amount - other, currency)
31
+ else
32
+ raise 'Cannot convert String into Numeric'
33
+ end
34
+ end
35
+
36
+ def +(other)
37
+ if other.is_a?(MoneyHdamico)
38
+ other.convert_to(currency) if other.currency != currency
39
+ MoneyHdamico.new(amount + other.amount, currency)
40
+ elsif other.is_a?(Numeric)
41
+ MoneyHdamico.new(amount + other, currency)
42
+ else
43
+ raise 'Cannot convert String into Numeric'
44
+ end
45
+ end
46
+
47
+ def /(other)
48
+ if other.is_a?(MoneyHdamico)
49
+ other.convert_to(currency) if other.currency != currency
50
+ MoneyHdamico.new(amount / other.amount, currency)
51
+ elsif other.is_a?(Numeric)
52
+ MoneyHdamico.new(amount / other, currency)
53
+ else
54
+ raise 'Cannot convert String into Numeric'
55
+ end
56
+ end
57
+
58
+ def *(other)
59
+ if other.is_a?(MoneyHdamico)
60
+ other.convert_to(currency) if other.currency != currency
61
+ MoneyHdamico.new(amount * other.amount, currency)
62
+ elsif other.is_a?(Numeric)
63
+ MoneyHdamico.new(amount * other, currency)
64
+ else
65
+ raise 'Cannot convert String into Numeric'
66
+ end
67
+ end
68
+
69
+ def <(other)
70
+ if other.is_a?(MoneyHdamico)
71
+ other.convert_to(currency) if other.currency != currency
72
+ return true if amount < other.amount
73
+ end
74
+ false
75
+ end
76
+
77
+ def >(other)
78
+ if other.is_a?(MoneyHdamico)
79
+ other.convert_to(currency) if other.currency != currency
80
+ return true if amount > other.amount
81
+ end
82
+ false
83
+ end
84
+
85
+ def ==(other)
86
+ if other.is_a?(MoneyHdamico)
87
+ return true if amount == other.amount && currency == other.currency
88
+ end
89
+ false
90
+ end
91
+ end
@@ -0,0 +1,5 @@
1
+ # lib/money_hdamico.rb
2
+ require "money"
3
+
4
+ module MoneyHdamico
5
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: money_hdamico
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Hernan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-13 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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
+ description: Interview gem development.
56
+ email:
57
+ - hernan.damico67@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/money.rb
63
+ - lib/money_hdamico.rb
64
+ homepage: https://gitlab.com/hdamico
65
+ licenses: []
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.0.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Interview gem development.
86
+ test_files: []