Class: Money

Inherits:
Object
  • Object
show all
Defined in:
lib/mm-money.rb

Class Method Summary collapse

Class Method Details

.from_mongo(value) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/mm-money.rb', line 16

def self.from_mongo(value)
  if value.kind_of?(Money)
    value
  elsif value.kind_of?(Array)
    Money.new(value.first, value.second)
  else
    nil
  end
end

.to_mongo(value) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/mm-money.rb', line 5

def self.to_mongo(value)
  if value.kind_of?(Array)
    value
  elsif value.nil? || !value.respond_to?(:to_money)
    nil
  else
    value = value.to_money
    [value.cents, value.currency.iso_code]
  end
end