Parent

Included Modules

Reckon::Money

Attributes

amount[RW]
currency[RW]
suffixed[RW]

Public Class Methods

from_s( value, options = {} ) click to toggle source
# File lib/reckon/money.rb, line 44
def Money::from_s( value, options = {} )
  return nil if value.empty?
  value = value.gsub(/\./, '').gsub(/,/, '.') if options[:comma_separates_cents]
  amount = value.gsub(/[^\d\.]/, '').to_f
  amount *= -1 if value =~ /[\(\-]/
  Money.new( amount, options )
end
likelihood( entry ) click to toggle source
# File lib/reckon/money.rb, line 52
def Money::likelihood( entry )
  money_score = 0
  money_score += 20 if entry[/^[\-\+\(]{0,2}\$/]
  money_score += 10 if entry[/^\$?\-?\$?\d+[\.,\d]*?[\.,]\d\d$/]
  money_score += 10 if entry[/\d+[\.,\d]*?[\.,]\d\d$/]
  money_score += entry.gsub(/[^\d\.\-\+,\(\)]/, '').length if entry.length < 7
  money_score -= entry.length if entry.length > 8
  money_score -= 20 if entry !~ /^[\$\+\.\-,\d\(\)]+$/
  money_score
end
new( amount, options = {} ) click to toggle source
# File lib/reckon/money.rb, line 7
def initialize( amount, options = {} )
  if options[:inverse]
    @amount = -1*amount.to_f
  else
    @amount = amount.to_f
  end
  @currency = options[:currency] || "$"
  @suffixed = options[:suffixed]
end

Public Instance Methods

-@() click to toggle source
# File lib/reckon/money.rb, line 21
def -@
  Money.new( -@amount, :currency => @currency, :suffixed => @suffixed )
end
<=>( mon ) click to toggle source
# File lib/reckon/money.rb, line 25
def <=>( mon )
  other_amount = mon.to_f
  if @amount < other_amount
    -1
  elsif @amount > other_amount
    1
  else
    0
  end
end
pretty( negate = false ) click to toggle source
# File lib/reckon/money.rb, line 36
def pretty( negate = false )
  if @suffixed
    (@amount >= 0 ? " " : "") + sprintf("%0.2f #{@currency}", @amount * (negate ? -1 : 1))
  else
    (@amount >= 0 ? " " : "") + sprintf("%0.2f", @amount * (negate ? -1 : 1)).gsub(/^((\-)|)(?=\d)/, "\\1#{@currency}")
  end      
end
to_f() click to toggle source
# File lib/reckon/money.rb, line 17
def to_f
  return @amount
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.