Class: KasPay::Money

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

Overview

Inner class Money

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = 0) ⇒ Money

Returns a new instance of Money.



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

def initialize value = 0
   @value = value.gsub(/\s/, '').sub(/[\.\,]00$/, "").sub(/^Rp\s*(.*)$/, '\1').gsub(/[\.\,]/, '').to_i
end

Instance Attribute Details

#valueObject Also known as: to_i

Returns the value of attribute value.



4
5
6
# File 'lib/kaspay/money.rb', line 4

def value
  @value
end

Instance Method Details

#inspectObject



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

def inspect
   "#<#{self.class}:0x#{(object_id << 1).to_s(16)} value=#{value}>"
end

#to_fObject



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

def to_f
   value * 1.0
end

#to_sObject



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

def to_s
   "Rp " + value.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse + ".00"
end