magic_money 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/magic_money.rb +4 -11
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4df3aa1b760c4164aea56c4190278e5287612aea
4
- data.tar.gz: d0cd121731127e7cb465236377ac04bba71a7a98
3
+ metadata.gz: 0701335975bac02888478471c5e13be5032e4e51
4
+ data.tar.gz: fee872e86645ea2a69bbb80a06c79c96d08c04c3
5
5
  SHA512:
6
- metadata.gz: 03da7c8f3ff0623841bf19425a45950c7f5ab0c378e5a2822fcb571e296b8b9a92e1fade95dbf9fcf7e7f567e1f68f34c1d72bb4605531e62bf01ab70f110b09
7
- data.tar.gz: 69fa46a7433dc20c05ae64194d81b87fd8814d564a7a4df3950b98710d0160fe7c23e0412138eb9afb4b6b9f5d3193135fd3db68d125699658b6e69f936bcad6
6
+ metadata.gz: 063570c93d3d8c274ad23188cad3c49ee45f6aaa50c379ac9ce85b43fb5f51558af046fda80e78788b80e51e9c133653c4d05b7dcd99bdea24ef4deabbf2168d
7
+ data.tar.gz: 9f1a4b57b67768e2355e4de5aa861a2fe3e2fd6a952999bc1ab75225efdfe2fa9d435f4d0822556a545528b228e2d6541e8584d2f91641f755c912cc46e83175
data/lib/magic_money.rb CHANGED
@@ -1,4 +1,8 @@
1
+ require 'magic_money/operators'
2
+
1
3
  class MagicMoney
4
+ include Operators
5
+
2
6
  attr_accessor :amount, :currency
3
7
 
4
8
  RATES = { 'EUR' => { 'USD' => 1.11, 'Bitcoin' => 0.0047 },
@@ -20,13 +24,6 @@ class MagicMoney
20
24
  MagicMoney.new(amount_in(new_currency), new_currency)
21
25
  end
22
26
 
23
- [:/, :*, :+, :-, :==, :>, :<].each do |operator|
24
- define_method(operator) do |value|
25
- result = @amount.send(operator, parse_operation_param(value))
26
- [true, false].include?(result) ? result : "#{ result } #{ @currency }"
27
- end
28
- end
29
-
30
27
  private
31
28
  def amount_as_money
32
29
  '%.2f' % @amount
@@ -36,10 +33,6 @@ class MagicMoney
36
33
  new_currency == @currency ? @amount : (@amount.to_f * RATES[@currency][new_currency]).round(2)
37
34
  end
38
35
 
39
- def parse_operation_param(value)
40
- value.kind_of?(MagicMoney) ? value.convert_to(@currency).amount : value
41
- end
42
-
43
36
  def validate_currency(currency)
44
37
  raise ArgumentError, 'Invalid currency' if RATES[currency].nil?
45
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magic_money
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anezio Campos