reckon 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 701e85b9ec558657003c57d9d33744840fcdcb55
4
- data.tar.gz: d343b374bf5375ec34a915a84b7a27724b53b995
3
+ metadata.gz: b3b4088d077cc7f00227616a72cb8b3ceee7ec6b
4
+ data.tar.gz: f0af12774c1ac656196e2ab6c4fd344a2cc09c1e
5
5
  SHA512:
6
- metadata.gz: 8489408851bf979388afb2f0ed8da24d30d738b82c83116f1551d8d1f43aebf17f4aeb9ad05a835323ca73199568b74265a556bb25e05c5f4f4585508d4aa863
7
- data.tar.gz: 1a6845f390988e12286716351029a015165fa5dc8230aa1d0021616aa4a4e108a8fea64b0249176698a0c8edf8b4e4b4991517028e6a156a2dfecfd04fe067a3
6
+ metadata.gz: 1f8fe4aa72b96c8deeff382b18c6dc3fdd8df5360b859e49891beed8522b79a135d0f8f4994bc5d90137457407fd68d567faa6f1b4837d96a6f006775a4387e8
7
+ data.tar.gz: 9d8cfe9ffab12fcc0e77af8e5f613ab12d9b403a5122ed42cf983cedc24696ec5b4df90ae046ab5575301e6f51f23522f516ace2782c8934c381d7e79a640b21
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- reckon (0.4.0)
4
+ reckon (0.4.1)
5
5
  chronic (>= 0.3.0)
6
6
  fastercsv (>= 1.5.1)
7
7
  highline (>= 1.5.2)
@@ -95,10 +95,9 @@ module Reckon
95
95
  output_columns = []
96
96
  columns.each_with_index do |column, index|
97
97
  if index == a
98
- new_column = []
99
- column.each_with_index do |row, row_index|
100
- new_column << row + " " + (columns[b][row_index] || '')
101
- end
98
+ new_column = MoneyColumn.new( column )
99
+ .merge!( MoneyColumn.new( columns[b] ) )
100
+ .map { |m| m.amount.to_s }
102
101
  output_columns << new_column
103
102
  elsif index == b
104
103
  # skip
@@ -43,11 +43,30 @@ module Reckon
43
43
  end
44
44
 
45
45
  def Money::from_s( value, options = {} )
46
- return nil if value.empty?
46
+ # Empty string is treated as money with value 0
47
+ return Money.new( 0.00, options ) if value.empty?
48
+
49
+ # Remove 1000 separaters and replace , with . if comma_separates_cents
50
+ # 1.000,00 -> 1000.00
47
51
  value = value.gsub(/\./, '').gsub(/,/, '.') if options[:comma_separates_cents]
48
- amount = value.gsub(/[^\d\.]/, '').to_f
49
- amount *= -1 if value =~ /[\(\-]/
50
- Money.new( amount, options )
52
+ value = value.gsub(/,/, '')
53
+
54
+ money_format_regex = /^(.*?)(\d+\.\d\d)/ # Money has two decimal precision
55
+ any_number_regex = /^(.*?)([\d\.]+)/
56
+
57
+ # Prefer matching the money_format, match any number otherwise
58
+ m = value.match( money_format_regex ) ||
59
+ value.match( any_number_regex )
60
+ if m
61
+ amount = m[2].to_f
62
+ # Check whether the money had a - or (, which indicates negative amounts
63
+ if (m[1].match( /^[\(-]/ ) || m[1].match( /-$/ ))
64
+ amount *= -1
65
+ end
66
+ return Money.new( amount, options )
67
+ else
68
+ return nil
69
+ end
51
70
  end
52
71
 
53
72
  def Money::likelihood( entry )
@@ -79,11 +98,12 @@ module Reckon
79
98
  invert = true if self.positive? && other_column.positive?
80
99
  self.each_with_index do |mon, i|
81
100
  other = other_column[i]
82
- if mon && !other
101
+ return nil if (!mon || !other)
102
+ if mon != 0.00 && other == 0.0
83
103
  if invert
84
104
  self[i]= -mon
85
105
  end
86
- elsif !mon && other
106
+ elsif mon == 0.00 && other != 0.00
87
107
  self[i] = other
88
108
  else
89
109
  return nil
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = %q{reckon}
6
- s.version = "0.4.0"
6
+ s.version = "0.4.1"
7
7
  s.authors = ["Andrew Cantino", "BlackEdder"]
8
8
  s.email = %q{andrew@iterationlabs.com}
9
9
  s.homepage = %q{https://github.com/cantino/reckon}
@@ -12,6 +12,7 @@ describe Reckon::CSVParser do
12
12
  @chase = Reckon::CSVParser.new(:string => CHASE_CSV)
13
13
  @some_other_bank = Reckon::CSVParser.new(:string => SOME_OTHER_CSV)
14
14
  @two_money_columns = Reckon::CSVParser.new(:string => TWO_MONEY_COLUMNS_BANK)
15
+ @suntrust_csv = Reckon::CSVParser.new(:string => SUNTRUST_CSV)
15
16
  @simple_csv = Reckon::CSVParser.new(:string => SIMPLE_CSV)
16
17
  @nationwide = Reckon::CSVParser.new( :string => NATIONWIDE_CSV, :csv_separator => ',', :suffixed => true, :currency => "POUND" )
17
18
  @german_date = Reckon::CSVParser.new(:string => GERMAN_DATE_EXAMPLE)
@@ -65,6 +66,7 @@ describe Reckon::CSVParser do
65
66
  @chase.money_column_indices.should == [3]
66
67
  @some_other_bank.money_column_indices.should == [3]
67
68
  @two_money_columns.money_column_indices.should == [3, 4]
69
+ @suntrust_csv.money_column_indices.should == [3, 4]
68
70
  @nationwide.money_column_indices.should == [3, 4]
69
71
  @harder_date_example_csv.money_column_indices.should == [1]
70
72
  @danish_kroner_nordea.money_column_indices.should == [3]
@@ -221,16 +223,6 @@ describe Reckon::CSVParser do
221
223
  end
222
224
  end
223
225
 
224
- describe "merge_columns" do
225
- it "should work on adjacent columns" do
226
- @simple_csv.merge_columns(0,1).should == [["entry1 entry2", "entry4 entry5"], ["entry3", "entry6"]]
227
- end
228
-
229
- it "should work on non-adjacent columns" do
230
- @simple_csv.merge_columns(0,2).should == [["entry1 entry3", "entry4 entry6"], ["entry2", "entry5"]]
231
- end
232
- end
233
-
234
226
  # Data
235
227
 
236
228
  SIMPLE_CSV = "entry1,entry2,entry3\nentry4,entry5,entry6"
@@ -286,6 +278,16 @@ describe Reckon::CSVParser do
286
278
  3/26/2008,Check - 0000000251,251,"","+$88.55","$1,298.57"
287
279
  CSV
288
280
 
281
+ SUNTRUST_CSV = (<<-CSV).strip
282
+ 11/01/2014,0, Deposit,0,500.00,500.00
283
+ 11/02/2014,101,Check,100.00,0,400.00
284
+ 11/03/2014,102,Check,100.00,0,300.00
285
+ 11/04/2014,103,Check,100.00,0,200.00
286
+ 11/05/2014,104,Check,100.00,0,100.00
287
+ 11/06/2014,105,Check,100.00,0,0.00
288
+ 11/17/2014,0, Deposit,0,700.00,700.00
289
+ CSV
290
+
289
291
  NATIONWIDE_CSV = (<<-CSV).strip
290
292
  07 Nov 2013,Bank credit,Bank credit,,£500.00,£500.00
291
293
  09 Oct 2013,ATM Withdrawal,Withdrawal,£20.00,,£480.00
@@ -35,11 +35,23 @@ describe Reckon::MoneyColumn do
35
35
  Reckon::MoneyColumn.new( ["1.00", ""] ).merge!(
36
36
  Reckon::MoneyColumn.new( ["", "-2.00"] ) ).should == [
37
37
  Reckon::Money.new( 1.00 ), Reckon::Money.new( -2.00 ) ]
38
- end
38
+ Reckon::MoneyColumn.new( ["1.00", "0"] ).merge!(
39
+ Reckon::MoneyColumn.new( ["0", "-2.00"] ) ).should == [
40
+ Reckon::Money.new( 1.00 ), Reckon::Money.new( -2.00 ) ]
41
+ Reckon::MoneyColumn.new( ["AB1.00C", ""] ).merge!(
42
+ Reckon::MoneyColumn.new( ["", "AB-2.00C"] ) ).should == [
43
+ Reckon::Money.new( 1.00 ), Reckon::Money.new( -2.00 ) ]
44
+ Reckon::MoneyColumn.new( ["AB1.00C", "AB0C"] ).merge!(
45
+ Reckon::MoneyColumn.new( ["AB0C", "AB-2.00C"] ) ).should == [
46
+ Reckon::Money.new( 1.00 ), Reckon::Money.new( -2.00 ) ]
47
+ end
39
48
 
40
49
  it "should return nil if columns cannot be merged" do
41
50
  Reckon::MoneyColumn.new( ["1.00", ""] ).merge!(
42
51
  Reckon::MoneyColumn.new( ["1.00", "-2.00"] ) ).should == nil
52
+
53
+ Reckon::MoneyColumn.new( ["From1", "Names"] ).merge!(
54
+ Reckon::MoneyColumn.new( ["Acc", "NL28 INGB 1200 3244 16,21817"] ) ).should == nil
43
55
  end
44
56
 
45
57
  it "should invert first column if both positive" do
@@ -19,15 +19,33 @@ describe Reckon::Money do
19
19
  Reckon::Money::from_s( "$-1025,67", :comma_separates_cents => true ).should == -1025.67
20
20
  end
21
21
 
22
- it "should return nil for an empty string" do
23
- Reckon::Money::from_s( "" ).should == nil
24
- Reckon::Money::from_s( "" ).should_not == 0
22
+ it "should return 0 for an empty string" do
23
+ Reckon::Money::from_s( "" ).should == 0
25
24
  end
26
25
 
27
26
  it "should handle 1000 indicators correctly" do
28
27
  Reckon::Money::from_s( "$2.000,00", :comma_separates_cents => true ).should == 2000.00
29
28
  Reckon::Money::from_s( "-$1,025.67" ).should == -1025.67
30
29
  end
30
+
31
+ it "should keep numbers together" do
32
+ Reckon::Money::from_s( "1A1" ).should == 1
33
+ end
34
+
35
+ it "should prefer numbers with precision of two" do
36
+ Reckon::Money::from_s( "1A2.00" ).should == 2
37
+ Reckon::Money::from_s( "2.00A1" ).should == 2
38
+ end
39
+
40
+ it "should handle arbitrary prefixes and postfixes" do
41
+ Reckon::Money::from_s( "AB1.00C" ).should == 1
42
+ Reckon::Money::from_s( "AB0C" ).should == 0
43
+ Reckon::Money::from_s( "AB-2.00C" ).should == -2
44
+ end
45
+
46
+ it "should return nil if no numbers are found" do
47
+ Reckon::Money::from_s( "BAC" ).should == nil
48
+ end
31
49
  end
32
50
 
33
51
  describe "pretty" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reckon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Cantino
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-05 00:00:00.000000000 Z
12
+ date: 2015-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec