class Farmoney::Money
Attributes
pence[R]
to_i[R]
Public Class Methods
new(pence)
click to toggle source
# File lib/farmoney/money.rb, line 12 def initialize(pence) @pence = BigDecimal(pence) end
Public Instance Methods
*(other)
click to toggle source
# File lib/farmoney/money.rb, line 44 def *(other) Money.new(pence * other) end
+(other)
click to toggle source
# File lib/farmoney/money.rb, line 31 def +(other) Money.new(pence + other.pence) end
-(other)
click to toggle source
# File lib/farmoney/money.rb, line 35 def -(other) Money.new(pence - other.pence) end
/(other)
click to toggle source
# File lib/farmoney/money.rb, line 39 def /(other) divisor = other.respond_to?(:pence) ? other.pence : other Money.new(pence / BigDecimal(divisor, 2)) end
attributes()
click to toggle source
# File lib/farmoney/money.rb, line 23 def attributes instance_variables.each.with_object({}) do |attribute, hash| hash[attribute_name(attribute)] = instance_variable_get(attribute) end end
Also aliased as: to_hash
to_s()
click to toggle source
# File lib/farmoney/money.rb, line 16 def to_s pounds = @pence / 100 pence = @pence % 100 format("£%.1i.%.2i", pounds, pence) end
Private Instance Methods
attribute_name(attribute)
click to toggle source
# File lib/farmoney/money.rb, line 50 def attribute_name(attribute) attribute.to_s.sub("@", "").to_sym end