Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/ofx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ def monetary_vars(*methods) #:nodoc:

module MonetarySupport
# Returns pennies for a given string amount, i.e:
# '-.45' => -45
# '-123.45' => -12345
# '123' => 12300
def pennies_for(amount)
return nil if amount == ""
int, fraction = amount.scan(/\d+/)
int, fraction = 0, int if amount.match(/^-?\./)
i = (fraction.to_s.strip =~ /[1-9]/) ? "#{int}#{fraction[0,2]}".to_i : int.to_i * 100
amount =~ /^\s*-\s*\d+/ ? -i : i
amount =~ /^\s*-\s*.?\d+/ ? -i : i
end


def original_method(meth) #:nodoc:
meth.to_s.sub('_in_pennies','').to_sym rescue nil
end
Expand Down
2 changes: 2 additions & 0 deletions test/test_ofx_parser.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'minitest/autorun'
require 'ofx-parser'
require 'pry'

class OfxParserTest < MiniTest::Unit::TestCase

Expand Down Expand Up @@ -459,6 +460,7 @@ def test_for_pennies
'1' => 100,
'1.0' => 100,
'-1.0' => -100,
'-.11' => -11,
'' => nil
}

Expand Down