-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Fix #42: Work with suntrust double column csv files #48
Changes from 10 commits
a7c952f
c8e60e0
95a3010
d3e9913
c796bc2
821b6a7
a2b53df
8950f47
f31b27f
354733f
2330452
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,11 +43,19 @@ def pretty( negate = false ) | |
end | ||
|
||
def Money::from_s( value, options = {} ) | ||
return nil if value.empty? | ||
return Money.new( 0.00, options ) 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 ) | ||
value = value.gsub(/,/, '') | ||
m = value.match( /(\D*)(\d+\.\d\d)(\D*)/ ) || value.match(/^(.*?)([\d\.]+)(\D*)$/) | ||
if m | ||
amount = m[2].to_f | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment about what this method is doing might be helpful. I'm having trouble following it. |
||
if (m[1].match( /^[\(-]/ ) || m[1].match( /-$/ )) | ||
amount *= -1 | ||
end | ||
return Money.new( amount, options ) | ||
else | ||
return nil | ||
end | ||
end | ||
|
||
def Money::likelihood( entry ) | ||
|
@@ -79,11 +87,12 @@ def merge!( other_column ) | |
invert = true if self.positive? && other_column.positive? | ||
self.each_with_index do |mon, i| | ||
other = other_column[i] | ||
if mon && !other | ||
return nil if (!mon || !other) | ||
if mon != 0.00 && other == 0.0 | ||
if invert | ||
self[i]= -mon | ||
end | ||
elsif !mon && other | ||
elsif mon == 0.00 && other != 0.00 | ||
self[i] = other | ||
else | ||
return nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,11 +35,23 @@ | |
Reckon::MoneyColumn.new( ["1.00", ""] ).merge!( | ||
Reckon::MoneyColumn.new( ["", "-2.00"] ) ).should == [ | ||
Reckon::Money.new( 1.00 ), Reckon::Money.new( -2.00 ) ] | ||
end | ||
Reckon::MoneyColumn.new( ["1.00", "0"] ).merge!( | ||
Reckon::MoneyColumn.new( ["0", "-2.00"] ) ).should == [ | ||
Reckon::Money.new( 1.00 ), Reckon::Money.new( -2.00 ) ] | ||
Reckon::MoneyColumn.new( ["AB1.00C", ""] ).merge!( | ||
Reckon::MoneyColumn.new( ["", "AB-2.00C"] ) ).should == [ | ||
Reckon::Money.new( 1.00 ), Reckon::Money.new( -2.00 ) ] | ||
Reckon::MoneyColumn.new( ["AB1.00C", "AB0C"] ).merge!( | ||
Reckon::MoneyColumn.new( ["AB0C", "AB-2.00C"] ) ).should == [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have an example CSV that has numbers in this format? It might be worth adding above... or is this the Suntrust one? I just don't see why that one was having issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no real example, but thought it was nice to allow arbitrary postfix/prefix with numbers in them. In many ways this is more for the columns that are likely to not be money, but something like account numbers. It will still parse them as money and give them the benefit of the doubt. I've updated the description of this PR to explain why the suntrust csv didn't work. |
||
Reckon::Money.new( 1.00 ), Reckon::Money.new( -2.00 ) ] | ||
end | ||
|
||
it "should return nil if columns cannot be merged" do | ||
Reckon::MoneyColumn.new( ["1.00", ""] ).merge!( | ||
Reckon::MoneyColumn.new( ["1.00", "-2.00"] ) ).should == nil | ||
|
||
Reckon::MoneyColumn.new( ["From1", "Names"] ).merge!( | ||
Reckon::MoneyColumn.new( ["Acc", "NL28 INGB 1200 3244 16,21817"] ) ).should == nil | ||
end | ||
|
||
it "should invert first column if both positive" do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could pull these Regexes into CONSTANTS with descriptive names?