monefy 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/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +134 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/monefy.rb +97 -0
- data/lib/monefy/arithmetic.rb +90 -0
- data/lib/monefy/converter.rb +41 -0
- data/lib/monefy/matchers.rb +69 -0
- data/lib/monefy/version.rb +3 -0
- data/monefy.gemspec +27 -0
- metadata +100 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f80d9004701e3d2aa7f6b356133cd02b87436710
|
|
4
|
+
data.tar.gz: 65ff94cf1affd47ec6b13f0adcd8c4d2562683e6
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0d67271662357e8e954a1c573e7b49aaa5ac4b056552ca904cc1e6f4eb290c5684a28963482246ac5caf78bf313054da37a2378135885cfd78e6b1df2596ef7b
|
|
7
|
+
data.tar.gz: ca0000483caa721e668103c3855e2c2c47b930d8b03c4b68e0bfb8f7bea9f9c65197821ea255f62bea428936a698c610a55132ae76c81599c993c46a7d874792
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Bruno Almeida
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
[](https://travis-ci.org/wwwbruno/monefy)
|
|
2
|
+
[](https://codeclimate.com/github/wwwbruno/monefy)
|
|
3
|
+
[](https://coveralls.io/github/wwwbruno/monefy?branch=master)
|
|
4
|
+
[](http://inch-ci.org/github/wwwbruno/monefy)
|
|
5
|
+
|
|
6
|
+
# Monefy
|
|
7
|
+
|
|
8
|
+
This gem will easily help you to perform currency conversion and arithmetics with different currencies.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Add this line to your application's Gemfile:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
gem 'monefy', github: 'wwwbruno/monefy'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
And then execute:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
$ bundle
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
#### Set your conversion rates on your Initialize file
|
|
27
|
+
```ruby
|
|
28
|
+
Monefy.conversion_rates('EUR', {
|
|
29
|
+
'USD' => 1.11,
|
|
30
|
+
'Bitcoin' => 0.0047
|
|
31
|
+
}) # => {"USD"=>1.11, "Bitcoin"=>0.0047, "EUR"=>1}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
#### Create a new Monefy instance passing amount and currency as initializer parameters
|
|
35
|
+
```ruby
|
|
36
|
+
fifty_eur = Monefy.new(50, 'EUR')
|
|
37
|
+
# => #<Monefy:0x... @amount=50.0, @currency="EUR">
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
#### Convert to another currencies
|
|
41
|
+
```ruby
|
|
42
|
+
fifty_eur.convert_to('USD')
|
|
43
|
+
# => #<Monefy:0x... @amount=55.5, @currency="USD">
|
|
44
|
+
fifty_eur.convert_to('Bitcoin')
|
|
45
|
+
# => #<Monefy:0x... @amount=0.24, @currency="Bitcoin">
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
#### Add and subtract with other Monefy instances with different currencies
|
|
49
|
+
```ruby
|
|
50
|
+
fifty_eur + Monefy.new(20, 'USD')
|
|
51
|
+
# => #<Monefy:0x... @amount=68.02, @currency="EUR">
|
|
52
|
+
fifty_eur - Monefy.new(0.03, 'Bitcoin')
|
|
53
|
+
# => #<Monefy:0x... @amount=43.62, @currency="EUR">
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### Multiply and divide
|
|
57
|
+
```ruby
|
|
58
|
+
fifty_eur / 2
|
|
59
|
+
# => #<Monefy:0x... @amount=25.0, @currency="EUR">
|
|
60
|
+
fifty_eur * 3
|
|
61
|
+
# => #<Monefy:0x... @amount=150.0, @currency="EUR">
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### Compare different currencies:
|
|
65
|
+
```ruby
|
|
66
|
+
fifty_eur > Monefy.new(54.55, 'USD') # => true
|
|
67
|
+
Monefy.new(180, 'USD') < Monefy.new(0.73, 'Bitcoin') # => false
|
|
68
|
+
Monefy.new(54.55, 'USD') == Monefy.new(49.14, 'EUR') # => true
|
|
69
|
+
Monefy.new(35, 'USD') != Monefy.new(49.14, 'EUR') # => true
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Exceptions
|
|
73
|
+
#### Instantiate class without setting conversion rates
|
|
74
|
+
```ruby
|
|
75
|
+
Monefy.new(50, 'USD')
|
|
76
|
+
# => StandardError: No conversion rates set
|
|
77
|
+
|
|
78
|
+
# Solution
|
|
79
|
+
# Set your conversion rates on your Initialize file
|
|
80
|
+
Monefy.conversion_rates('EUR', {
|
|
81
|
+
'USD' => 1.11,
|
|
82
|
+
'Bitcoin' => 0.0047
|
|
83
|
+
}) # => {"USD"=>1.11, "Bitcoin"=>0.0047, "EUR"=>1}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### Instantiate class or call convert_to to method with invalid current
|
|
87
|
+
```ruby
|
|
88
|
+
Monefy.new(50, 'INVALID-CURRENCY')
|
|
89
|
+
# => StandardError: "Invalid currency"
|
|
90
|
+
|
|
91
|
+
Monefy.new(50, 'EUR').convert_to('INVALID-CURRENCY')
|
|
92
|
+
# => StandardError: "Invalid currency"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### Compare Monefy instance without another Monefy instance
|
|
96
|
+
```ruby
|
|
97
|
+
Monefy.new(50, 'EUR') == 50
|
|
98
|
+
# => StandardError: "Not a Monefy instance"
|
|
99
|
+
|
|
100
|
+
Monefy.new(50, 'EUR') > "40.0 EUR"
|
|
101
|
+
# => StandardError: "Not a Monefy instance"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Adding or subtracting a Monefy instance without another Monefy instance
|
|
105
|
+
```ruby
|
|
106
|
+
Monefy.new(50, 'EUR') + 50
|
|
107
|
+
# => StandardError: "Not a Monefy instance"
|
|
108
|
+
|
|
109
|
+
Monefy.new(50, 'EUR') - "40.0 EUR"
|
|
110
|
+
# => StandardError: "Not a Monefy instance"
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### Splitting or multiplying a Monefy instance without a Numeric
|
|
114
|
+
```ruby
|
|
115
|
+
Monefy.new(50, 'EUR') / Monefy.new(15, 'EUR')
|
|
116
|
+
# => StandardError: "Not a numeric"
|
|
117
|
+
|
|
118
|
+
Monefy.new(50, 'EUR') * "40.0 EUR"
|
|
119
|
+
# => StandardError: "Not a numeric"
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Development
|
|
123
|
+
|
|
124
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
125
|
+
|
|
126
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
127
|
+
|
|
128
|
+
## Contributing
|
|
129
|
+
|
|
130
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wwwbruno/monefy.
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "monefy"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/monefy.rb
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require "monefy/converter"
|
|
2
|
+
require "monefy/matchers"
|
|
3
|
+
require "monefy/arithmetic"
|
|
4
|
+
require "monefy/version"
|
|
5
|
+
|
|
6
|
+
# Monefy instance with two attr_reader
|
|
7
|
+
#
|
|
8
|
+
# @attr_reader amount [Float] is the quantiy of a currency.
|
|
9
|
+
# @attr_reader currency [String] is the string correspondent to the currency.
|
|
10
|
+
class Monefy
|
|
11
|
+
include Monefy::Converter
|
|
12
|
+
include Monefy::Matchers
|
|
13
|
+
include Monefy::Arithmetic
|
|
14
|
+
|
|
15
|
+
attr_reader :amount, :currency
|
|
16
|
+
|
|
17
|
+
# To create a new instance, pass amout and current as parameters
|
|
18
|
+
#
|
|
19
|
+
# @param amount [Integer, Float] quantiy of a currency.
|
|
20
|
+
# @param currency [String] currency key created on `conversion_rates` method.
|
|
21
|
+
#
|
|
22
|
+
# @return [Monefy] all currencies conversion rate.
|
|
23
|
+
#
|
|
24
|
+
# @example
|
|
25
|
+
# Monefy.new(50, 'EUR') # => #<Monefy:0x... @amount=50.0, @currency="EUR">
|
|
26
|
+
#
|
|
27
|
+
# See 'self.conversion_rates' methdo before initializa a new instance
|
|
28
|
+
def initialize(amount, currency)
|
|
29
|
+
validate_currencies_rates
|
|
30
|
+
validate_currency(currency)
|
|
31
|
+
|
|
32
|
+
@amount = amount.round(2)
|
|
33
|
+
@currency = currency
|
|
34
|
+
|
|
35
|
+
self
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Set default currencies and conversion rates
|
|
39
|
+
# used to calculate conversions.
|
|
40
|
+
#
|
|
41
|
+
# Use this method on your initilizer application
|
|
42
|
+
# config
|
|
43
|
+
#
|
|
44
|
+
# @param main_currency [String] main currency.
|
|
45
|
+
# @param other_currencies [Hash] currencies relatives to main currency with
|
|
46
|
+
# key with other currency and value with conversion rate.
|
|
47
|
+
#
|
|
48
|
+
# @return [Hash] all currencies conversion rate.
|
|
49
|
+
#
|
|
50
|
+
# @example
|
|
51
|
+
# Monefy.conversion_rates('EUR', {
|
|
52
|
+
# 'USD' => 1.11,
|
|
53
|
+
# 'Bitcoin' => 0.0047
|
|
54
|
+
# }) # => {"USD"=>1.11, "Bitcoin"=>0.0047, "EUR"=>1}
|
|
55
|
+
def self.conversion_rates(main_currency, other_currencies)
|
|
56
|
+
@@currencies_rates = other_currencies.merge({ main_currency => 1 })
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Return Monefy instance string value
|
|
60
|
+
#
|
|
61
|
+
# @return [String] currency and amout string.
|
|
62
|
+
#
|
|
63
|
+
# @example
|
|
64
|
+
# Monefy.new(50, 'EUR').to_s # => "50.00 EUR"
|
|
65
|
+
# "#{Monefy.new(50, 'EUR')}" # => "50.00 EUR"
|
|
66
|
+
def to_s
|
|
67
|
+
"#{'%.02f' % amount} #{currency}"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
def validate_currencies_rates
|
|
73
|
+
return if @@currencies_rates.present?
|
|
74
|
+
|
|
75
|
+
raise StandardError, "No conversion rates set"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def validate_currency(currency)
|
|
79
|
+
return if @@currencies_rates.key? currency
|
|
80
|
+
|
|
81
|
+
raise StandardError, "Invalid currency"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def validate_monefy_instance(monefy)
|
|
85
|
+
return if monefy.instance_of? Monefy
|
|
86
|
+
|
|
87
|
+
raise StandardError, "Not a Monefy instance"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def currencies_rates
|
|
91
|
+
@@currencies_rates
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def create_new_instace(new_amount, new_currency)
|
|
95
|
+
self.class.new(new_amount, new_currency)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
class Monefy
|
|
2
|
+
# Encapsulate all the logic to handle basics arithmetic between two instances.
|
|
3
|
+
module Arithmetic
|
|
4
|
+
|
|
5
|
+
# Sum two Monefy instances
|
|
6
|
+
#
|
|
7
|
+
# @param monefy [Monefy] another Monefy instance.
|
|
8
|
+
#
|
|
9
|
+
# @return [Monefy] new Monefy instance with added amount.
|
|
10
|
+
#
|
|
11
|
+
# @example
|
|
12
|
+
# Monefy.new(50, 'EUR') + Monefy.new(20, 'USD')
|
|
13
|
+
# => #<Monefy:0x... @amount=68.02, @currency="EUR">
|
|
14
|
+
def + monefy
|
|
15
|
+
validate_monefy_instance(monefy)
|
|
16
|
+
|
|
17
|
+
calculated_amount = amount + converted_money_currency(monefy)
|
|
18
|
+
create_new_instace(
|
|
19
|
+
calculated_amount,
|
|
20
|
+
currency
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Subtract two Monefy instances
|
|
25
|
+
#
|
|
26
|
+
# @param monefy [Monefy] another Monefy instance.
|
|
27
|
+
#
|
|
28
|
+
# @return [Monefy] new Monefy instance with subtracted amount.
|
|
29
|
+
#
|
|
30
|
+
# @example
|
|
31
|
+
# Monefy.new(50, 'EUR') - Monefy.new(20, 'USD')
|
|
32
|
+
# => #<Monefy:0x... @amount=31.98, @currency="EUR">
|
|
33
|
+
def - monefy
|
|
34
|
+
validate_monefy_instance(monefy)
|
|
35
|
+
|
|
36
|
+
calculated_amount = amount - converted_money_currency(monefy)
|
|
37
|
+
create_new_instace(
|
|
38
|
+
calculated_amount,
|
|
39
|
+
currency
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Split a Monefy instances amount
|
|
44
|
+
#
|
|
45
|
+
# @param value [Integer, Float] value to split the Monefy instance amount.
|
|
46
|
+
#
|
|
47
|
+
# @return [Monefy] new Monefy instance with splited amount.
|
|
48
|
+
#
|
|
49
|
+
# @example
|
|
50
|
+
# Monefy.new(50, 'EUR') / 2
|
|
51
|
+
# => #<Monefy:0x... @amount=25, @currency="EUR">
|
|
52
|
+
def / value
|
|
53
|
+
validate_arithmetic_value(value)
|
|
54
|
+
|
|
55
|
+
calculated_amount = amount / value
|
|
56
|
+
create_new_instace(
|
|
57
|
+
calculated_amount,
|
|
58
|
+
currency
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Multiply a Monefy instances amount
|
|
63
|
+
#
|
|
64
|
+
# @param value [Integer, Float] value to multiply the Monefy instance
|
|
65
|
+
# amount.
|
|
66
|
+
#
|
|
67
|
+
# @return [Monefy] new Monefy instance with multiplied amount.
|
|
68
|
+
#
|
|
69
|
+
# @example
|
|
70
|
+
# Monefy.new(50, 'EUR') * 3
|
|
71
|
+
# => #<Monefy:0x... @amount=150, @currency="EUR">
|
|
72
|
+
def * value
|
|
73
|
+
validate_arithmetic_value(value)
|
|
74
|
+
|
|
75
|
+
calculated_amount = amount * value
|
|
76
|
+
create_new_instace(
|
|
77
|
+
calculated_amount,
|
|
78
|
+
currency
|
|
79
|
+
)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
private
|
|
83
|
+
|
|
84
|
+
def validate_arithmetic_value(value)
|
|
85
|
+
return if value.is_a? Numeric
|
|
86
|
+
|
|
87
|
+
raise StandardError, "Not a numeric"
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
class Monefy
|
|
2
|
+
# Encapsulate all the logic to convet currencies
|
|
3
|
+
module Converter
|
|
4
|
+
|
|
5
|
+
# Converts a Monefy instance froma a currency to another.
|
|
6
|
+
#
|
|
7
|
+
# @param to_currency [String] currency to be converted to.
|
|
8
|
+
#
|
|
9
|
+
# @return [Monefy] new Monefy instance converted to another currency.
|
|
10
|
+
#
|
|
11
|
+
# @example
|
|
12
|
+
# eur = Monefy.new(50, 'EUR')
|
|
13
|
+
# eur.convert_to('USD') # => #<Monefy:0x... @amount=55, @currency="USD">
|
|
14
|
+
def convert_to(to_currency)
|
|
15
|
+
validate_currency(to_currency)
|
|
16
|
+
|
|
17
|
+
calculated_amount = convert_currency(currency, amount, to_currency)
|
|
18
|
+
create_new_instace(
|
|
19
|
+
calculated_amount,
|
|
20
|
+
to_currency
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def converted_money_currency(money)
|
|
27
|
+
convert_currency(
|
|
28
|
+
money.currency,
|
|
29
|
+
money.amount,
|
|
30
|
+
currency
|
|
31
|
+
).round(2)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def convert_currency(from_currency, from_amount, to_currency)
|
|
35
|
+
to_currency_rate = currencies_rates[to_currency]
|
|
36
|
+
from_currency_rate = currencies_rates[from_currency]
|
|
37
|
+
|
|
38
|
+
(to_currency_rate * from_amount) / from_currency_rate
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
class Monefy
|
|
2
|
+
# Encapsulate all the logic to compare differente Monefy instances
|
|
3
|
+
module Matchers
|
|
4
|
+
|
|
5
|
+
# Check if two distinct Monefy instances are equal.
|
|
6
|
+
#
|
|
7
|
+
# @param monefy [Monefy] another Monefy instance.
|
|
8
|
+
#
|
|
9
|
+
# @return [Boolean] true if both instances are equal and false if they
|
|
10
|
+
# are different.
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# Monefy.new(50, 'EUR') == Monefy.new(40, 'EUR') # => false
|
|
14
|
+
# Monefy.new(50, 'EUR') == Monefy.new(55.5, 'USD') # => true
|
|
15
|
+
def == monefy
|
|
16
|
+
validate_monefy_instance(monefy)
|
|
17
|
+
|
|
18
|
+
amount == converted_money_currency(monefy)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Check if two distinct Monefy instances are different.
|
|
22
|
+
#
|
|
23
|
+
# @param monefy [Monefy] another Monefy instance.
|
|
24
|
+
#
|
|
25
|
+
# @return [Boolean] true if both instances are different and false if they
|
|
26
|
+
# are equal.
|
|
27
|
+
#
|
|
28
|
+
# @example
|
|
29
|
+
# Monefy.new(50, 'EUR') != Monefy.new(40, 'EUR') # => true
|
|
30
|
+
# Monefy.new(50, 'EUR') != Monefy.new(55.5, 'USD') # => false
|
|
31
|
+
def != monefy
|
|
32
|
+
validate_monefy_instance(monefy)
|
|
33
|
+
|
|
34
|
+
amount != converted_money_currency(monefy)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Check if one Monefy instance is greater than another.
|
|
38
|
+
#
|
|
39
|
+
# @param monefy [Monefy] another Monefy instance.
|
|
40
|
+
#
|
|
41
|
+
# @return [Boolean] true if current instace is greater than another and
|
|
42
|
+
# false if not.
|
|
43
|
+
#
|
|
44
|
+
# @example
|
|
45
|
+
# Monefy.new(50, 'EUR') > Monefy.new(40, 'EUR') # => true
|
|
46
|
+
# Monefy.new(50, 'EUR') > Monefy.new(200, 'USD') # => false
|
|
47
|
+
def > monefy
|
|
48
|
+
validate_monefy_instance(monefy)
|
|
49
|
+
|
|
50
|
+
amount > converted_money_currency(monefy)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Check if one Monefy instance is less than another.
|
|
54
|
+
#
|
|
55
|
+
# @param monefy [Monefy] another Monefy instance.
|
|
56
|
+
#
|
|
57
|
+
# @return [Boolean] true if current instace is less than another and
|
|
58
|
+
# false if not.
|
|
59
|
+
#
|
|
60
|
+
# @example
|
|
61
|
+
# Monefy.new(50, 'EUR') < Monefy.new(40, 'EUR') # => false
|
|
62
|
+
# Monefy.new(50, 'EUR') < Monefy.new(200, 'USD') # => true
|
|
63
|
+
def < monefy
|
|
64
|
+
validate_monefy_instance(monefy)
|
|
65
|
+
|
|
66
|
+
amount < converted_money_currency(monefy)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
data/monefy.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "monefy/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "monefy"
|
|
8
|
+
spec.version = Monefy::VERSION
|
|
9
|
+
spec.authors = ["Bruno Almeida"]
|
|
10
|
+
spec.email = ["brunom.almd@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "Perform currency conversion and arithmetics with different currencies."
|
|
13
|
+
spec.description = "Perform currency conversion and arithmetics with different currencies."
|
|
14
|
+
spec.homepage = "https://github.com/wwwbruno/monefy"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
spec.bindir = "exe"
|
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: monefy
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Bruno Almeida
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-06-18 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.15'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.15'
|
|
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: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ~>
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ~>
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5.0'
|
|
55
|
+
description: Perform currency conversion and arithmetics with different currencies.
|
|
56
|
+
email:
|
|
57
|
+
- brunom.almd@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- .gitignore
|
|
63
|
+
- .travis.yml
|
|
64
|
+
- Gemfile
|
|
65
|
+
- LICENSE.txt
|
|
66
|
+
- README.md
|
|
67
|
+
- Rakefile
|
|
68
|
+
- bin/console
|
|
69
|
+
- bin/setup
|
|
70
|
+
- lib/monefy.rb
|
|
71
|
+
- lib/monefy/arithmetic.rb
|
|
72
|
+
- lib/monefy/converter.rb
|
|
73
|
+
- lib/monefy/matchers.rb
|
|
74
|
+
- lib/monefy/version.rb
|
|
75
|
+
- monefy.gemspec
|
|
76
|
+
homepage: https://github.com/wwwbruno/monefy
|
|
77
|
+
licenses:
|
|
78
|
+
- MIT
|
|
79
|
+
metadata: {}
|
|
80
|
+
post_install_message:
|
|
81
|
+
rdoc_options: []
|
|
82
|
+
require_paths:
|
|
83
|
+
- lib
|
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - '>='
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
|
+
requirements:
|
|
91
|
+
- - '>='
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
94
|
+
requirements: []
|
|
95
|
+
rubyforge_project:
|
|
96
|
+
rubygems_version: 2.0.14.1
|
|
97
|
+
signing_key:
|
|
98
|
+
specification_version: 4
|
|
99
|
+
summary: Perform currency conversion and arithmetics with different currencies.
|
|
100
|
+
test_files: []
|