Class: Money::Base

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/money/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount, currency) ⇒ Base

Returns a new instance of Base.



7
8
9
# File 'lib/money/base.rb', line 7

def initialize(amount, currency)
  @amount, @currency = amount, currency
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



5
6
7
# File 'lib/money/base.rb', line 5

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



5
6
7
# File 'lib/money/base.rb', line 5

def currency
  @currency
end

Instance Method Details

#*(other) ⇒ Object



31
32
33
# File 'lib/money/base.rb', line 31

def *(other)
  arith(:*, other)
end

#+(other) ⇒ Object



23
24
25
# File 'lib/money/base.rb', line 23

def +(other)
  arith(:+, other)
end

#-(other) ⇒ Object



27
28
29
# File 'lib/money/base.rb', line 27

def -(other)
  arith(:-, other)
end

#/(other) ⇒ Object



35
36
37
# File 'lib/money/base.rb', line 35

def /(other)
  arith(:/, other)
end

#<=>(other) ⇒ Object



19
20
21
# File 'lib/money/base.rb', line 19

def <=>(other)
  @amount <=> other.convert_to(@currency).amount
end

#convert_to(to_curr) ⇒ Object



15
16
17
# File 'lib/money/base.rb', line 15

def convert_to(to_curr)
  self.class.new(convert(to_curr), to_curr)
end

#inspectObject



11
12
13
# File 'lib/money/base.rb', line 11

def inspect
  "#{@amount} #{@currency}"
end