Class: KasPay::Money
- Inherits:
-
Object
- Object
- KasPay::Money
- Defined in:
- lib/kaspay/money.rb
Overview
Inner class Money
Instance Attribute Summary collapse
-
#value ⇒ Object
(also: #to_i)
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value = 0) ⇒ Money
constructor
A new instance of Money.
- #inspect ⇒ Object
- #to_f ⇒ Object
- #to_s ⇒ Object
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
#value ⇒ Object 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
#inspect ⇒ Object
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_f ⇒ Object
23 24 25 |
# File 'lib/kaspay/money.rb', line 23 def to_f value * 1.0 end |
#to_s ⇒ Object
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 |