Class: Egg::Money

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

Instance Method Summary collapse

Constructor Details

#initialize(money) ⇒ Money

Returns a new instance of Money.



3
4
5
6
7
8
# File 'lib/egg/money.rb', line 3

def initialize(money)
  money = money.sub(/£/, '').gsub(/,/, '')
  md = money.match(/(\d+\.\d+) ([A-Z]+)/)
  @money = md ? Float(md[1]) : 0
  @money = -@money if md && md[2] == 'DR'
end

Instance Method Details

#to_fObject



9
10
11
# File 'lib/egg/money.rb', line 9

def to_f
  @money
end