Module: Mint::MoneyAttribute

Extended by:
ActiveSupport::Concern
Defined in:
lib/minting/money_attribute/money_attribute.rb,
lib/minting/money_attribute/version.rb

Overview

MoneyAttribute

Constant Summary collapse

VERSION =
'0.3.3'

Class Method Summary collapse

Class Method Details

.parse(amount, currency) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/minting/money_attribute/money_attribute.rb', line 41

def self.parse(amount, currency)
  money = case amount
          when NilClass
            nil
          when Mint::Money
            amount
          when Numeric
            Mint.money(amount, currency)
          else
            if amount.respond_to? :to_money
              amount.to_money(currency)
            else
              Mint.money(amount.to_s.split[0].to_r, currency)
            end
          end
  # puts "parse(#{amount}, #{currency.inspect}) => #{money.inspect}"
  Mint.assert_valid_currency!(currency)
  money
end