Class: Qiflib::Money

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

Overview

Instances of this class represent a dollar amount values from within a qif file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s = '0.00') ⇒ Money

Returns a new instance of Money.



10
11
12
13
14
15
16
17
18
# File 'lib/qiflib_money.rb', line 10

def initialize(s='0.00')
  @string_value = "#{s}".tr('TBL, ' , '') 
  if @string_value.size < 1
    @string_value = '0.00'
  end
  if @string_value.end_with?('.')
    @string_value = "#{string_value}00"
  end
end

Instance Attribute Details

#string_valueObject (readonly)

Returns the value of attribute string_value.



8
9
10
# File 'lib/qiflib_money.rb', line 8

def string_value
  @string_value
end

Instance Method Details

#centsObject



24
25
26
# File 'lib/qiflib_money.rb', line 24

def cents
  string_value.tr("$.","").to_i
end

#to_sObject



20
21
22
# File 'lib/qiflib_money.rb', line 20

def to_s
  @string_value
end