moolah 5.0.0 → 5.3.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 +4 -4
 - data/lib/moolah/formatter.rb +1 -1
 - data/lib/moolah/money.rb +21 -11
 - data/lib/moolah/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 259bd848b9c02a4cbec6ae4b48100192caff0c00b9315c82a6dd7b81372711cc
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ac0a29f2335095310e45bc3a597d7a4c7db644e7f15d9262d0f05fd5717d1965
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 706e6c87160955d2cc3cde1e238e79a7f6c0e2a66d2159591dd0227c4008e4ac30cf7aee1f235b0da3f771f3444393de86642390d50ee2d1f669d9837a1bd2a5
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c2b621ca8644131cab99bdf0e13b16447e257472235c54917865bb03695e6af8b92f5343febef98296c69ca86cbecfdca5d95b52e0bd0991942edb9d2500aaed
         
     | 
    
        data/lib/moolah/formatter.rb
    CHANGED
    
    
    
        data/lib/moolah/money.rb
    CHANGED
    
    | 
         @@ -7,11 +7,12 @@ module Moolah 
     | 
|
| 
       7 
7 
     | 
    
         
             
                include Comparable
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
                attribute :amount, BigDecimal, default: BigDecimal(0)
         
     | 
| 
       10 
     | 
    
         
            -
                attribute :currency, String 
     | 
| 
      
 10 
     | 
    
         
            +
                attribute :currency, String
         
     | 
| 
       11 
11 
     | 
    
         
             
                attribute :fx_rate, BigDecimal
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
                def initialize(args = {})
         
     | 
| 
       14 
     | 
    
         
            -
                  args[: 
     | 
| 
      
 14 
     | 
    
         
            +
                  args[:currency] = 'AUD' if args[:currency].nil? || args[:currency] == ''
         
     | 
| 
      
 15 
     | 
    
         
            +
                  args[:fx_rate] = '1.0000' if args[:currency] == 'AUD'
         
     | 
| 
       15 
16 
     | 
    
         | 
| 
       16 
17 
     | 
    
         
             
                  raise ArgumentError.new('missing keyword: :fx_rate') unless args[:fx_rate]
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
         @@ -34,6 +35,10 @@ module Moolah 
     | 
|
| 
       34 
35 
     | 
    
         
             
                  formatter.format(symbol: false, delimit: false)
         
     | 
| 
       35 
36 
     | 
    
         
             
                end
         
     | 
| 
       36 
37 
     | 
    
         | 
| 
      
 38 
     | 
    
         
            +
                def formatted_fx_rate
         
     | 
| 
      
 39 
     | 
    
         
            +
                  formatter.format_fx_rate
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
       37 
42 
     | 
    
         
             
                def amount_in_cents
         
     | 
| 
       38 
43 
     | 
    
         
             
                  (bankers_rounded.amount * 100).to_i
         
     | 
| 
       39 
44 
     | 
    
         
             
                end
         
     | 
| 
         @@ -56,18 +61,22 @@ module Moolah 
     | 
|
| 
       56 
61 
     | 
    
         | 
| 
       57 
62 
     | 
    
         
             
                def +(money)
         
     | 
| 
       58 
63 
     | 
    
         
             
                  return self unless money
         
     | 
| 
       59 
     | 
    
         
            -
                  raise ArgumentError, 'Cannot add two Money objects with different currencies' if currency != money.currency
         
     | 
| 
       60 
     | 
    
         
            -
                  raise ArgumentError, 'Cannot add two Money objects with different fx rates' if fx_rate != money.fx_rate
         
     | 
| 
       61 
64 
     | 
    
         | 
| 
       62 
     | 
    
         
            -
                   
     | 
| 
      
 65 
     | 
    
         
            +
                  new_money = money.is_a?(Moolah::Money) ? money : Moolah::Money.new(money)
         
     | 
| 
      
 66 
     | 
    
         
            +
                  raise ArgumentError, "Cannot add currency: #{currency} with given currency: #{new_money.currency}" if currency != new_money.currency
         
     | 
| 
      
 67 
     | 
    
         
            +
                  raise ArgumentError, "Cannot add fx rate: #{formatter.format_fx_rate} with given fx rate: #{new_money.formatted_fx_rate}" if fx_rate != new_money.fx_rate
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                  Money.new(amount: amount + new_money.amount, currency: currency, fx_rate: fx_rate)
         
     | 
| 
       63 
70 
     | 
    
         
             
                end
         
     | 
| 
       64 
71 
     | 
    
         | 
| 
       65 
72 
     | 
    
         
             
                def -(money)
         
     | 
| 
       66 
73 
     | 
    
         
             
                  return self unless money
         
     | 
| 
       67 
     | 
    
         
            -
                  raise ArgumentError, 'Cannot subtract two Money objects with different currencies' if currency != money.currency
         
     | 
| 
       68 
     | 
    
         
            -
                  raise ArgumentError, 'Cannot subtract two Money objects with different fx rates' if fx_rate != money.fx_rate
         
     | 
| 
       69 
74 
     | 
    
         | 
| 
       70 
     | 
    
         
            -
                   
     | 
| 
      
 75 
     | 
    
         
            +
                  new_money = money.is_a?(Moolah::Money) ? money : Moolah::Money.new(money)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  raise ArgumentError, "Cannot subtract currency: #{currency} with given currency: #{new_money.currency}" if currency != new_money.currency
         
     | 
| 
      
 77 
     | 
    
         
            +
                  raise ArgumentError, "Cannot subtract fx rate: #{formatter.format_fx_rate} with given fx rate: #{new_money.formatted_fx_rate}" if fx_rate != new_money.fx_rate
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                  Money.new(amount: amount - new_money.amount, currency: currency, fx_rate: fx_rate)
         
     | 
| 
       71 
80 
     | 
    
         
             
                end
         
     | 
| 
       72 
81 
     | 
    
         | 
| 
       73 
82 
     | 
    
         
             
                def *(_money)
         
     | 
| 
         @@ -83,10 +92,11 @@ module Moolah 
     | 
|
| 
       83 
92 
     | 
    
         
             
                end
         
     | 
| 
       84 
93 
     | 
    
         | 
| 
       85 
94 
     | 
    
         
             
                def <=>(money)
         
     | 
| 
       86 
     | 
    
         
            -
                   
     | 
| 
       87 
     | 
    
         
            -
                  raise ArgumentError,  
     | 
| 
      
 95 
     | 
    
         
            +
                  new_money = money.is_a?(Moolah::Money) ? money : Moolah::Money.new(money)
         
     | 
| 
      
 96 
     | 
    
         
            +
                  raise ArgumentError, "Cannot compare currency: #{currency} with given currency: #{money.currency}" if currency != new_money.currency
         
     | 
| 
      
 97 
     | 
    
         
            +
                  raise ArgumentError, "Cannot compare fx rate: #{formatter.format_fx_rate} with given fx rate: #{new_money.formatted_fx_rate}" if fx_rate != new_money.fx_rate
         
     | 
| 
       88 
98 
     | 
    
         | 
| 
       89 
     | 
    
         
            -
                  amount <=>  
     | 
| 
      
 99 
     | 
    
         
            +
                  amount <=> new_money.amount
         
     | 
| 
       90 
100 
     | 
    
         
             
                end
         
     | 
| 
       91 
101 
     | 
    
         | 
| 
       92 
102 
     | 
    
         
             
                def bankers_rounded
         
     | 
    
        data/lib/moolah/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: moolah
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 5. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 5.3.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Marc Lee
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire:
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2022-07- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2022-07-24 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: bundler
         
     |