reckon 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,6 +5,9 @@
5
5
  *.tmproj
6
6
  tmtags
7
7
 
8
+ ## SUBLIME
9
+ *.sublime-project
10
+
8
11
  ## EMACS
9
12
  *~
10
13
  \#*
data/CHANGES.md ADDED
@@ -0,0 +1,3 @@
1
+ # Changes
2
+
3
+ * 3/24/13 - Force encoding to UTF-8 when unknown characters are encountered.
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Reckon
2
2
 
3
- Reckon automagically converts CSV files for use with the command-line accounting tool Ledger[https://github.com/jwiegley/ledger/wiki]. It also helps you to select the correct accounts associated with the CSV data using Bayesian machine learning.
3
+ Reckon automagically converts CSV files for use with the command-line accounting tool [Ledger](https://github.com/jwiegley/ledger/wiki). It also helps you to select the correct accounts associated with the CSV data using Bayesian machine learning.
4
4
 
5
5
  ## Installation
6
6
 
7
- Assuming you have Ruby and Rubygems[http://rubygems.org/pages/download] installed on your system, simply run
7
+ Assuming you have Ruby and [Rubygems](http://rubygems.org/pages/download) installed on your system, simply run
8
8
 
9
9
  (sudo) gem install reckon
10
10
 
@@ -16,6 +16,8 @@ To see how the CSV parses:
16
16
 
17
17
  reckon -f bank.csv -p
18
18
 
19
+ If your CSV file has a header on the first line, include `--contains-header`.
20
+
19
21
  To convert to ledger format and label everything, do:
20
22
 
21
23
  reckon -f bank.csv -o output.dat
@@ -24,11 +26,29 @@ To have reckon learn from an existing ledger file, provide it with -l:
24
26
 
25
27
  reckon -f bank.csv -l 2010.dat -o output.dat
26
28
 
27
- Learn more with
28
-
29
- reckon -h
30
-
31
- If you find CSV files that it can't parse, send me examples and I'll try to fix it.
29
+ Learn more:
30
+
31
+ > reckon -h
32
+
33
+ Usage: Reckon.rb [options]
34
+
35
+ -f, --file FILE The CSV file to parse
36
+ -v, --[no-]verbose Run verbosely
37
+ -p, --print-table Print out the parsed CSV in table form
38
+ -o, --output-file FILE The ledger file to append to
39
+ -l, --learn-from FILE An existing ledger file to learn accounts from
40
+ --ignore-columns 1,2,5
41
+ Columns to ignore in the CSV file - the first column is column 1
42
+ --contains-header
43
+ The first row of the CSV is a header and should be skipped
44
+ --csv-separator ','
45
+ Separator for parsing the CSV - default is comma.
46
+ --comma-separates-cents
47
+ Use comma instead of period to deliminate dollars from cents when parsing ($100,50 instead of $100.50)
48
+ -h, --help Show this message
49
+ --version Show version
50
+
51
+ If you find CSV files that it can't parse, send me examples or pull requests!
32
52
 
33
53
  ## Note on Patches/Pull Requests
34
54
 
data/lib/reckon/app.rb CHANGED
@@ -159,6 +159,7 @@ module Reckon
159
159
  value = value.gsub(/\./, '').gsub(/,/, '.') if options[:comma_separates_cents]
160
160
  cleaned_value = value.gsub(/[^\d\.]/, '').to_f
161
161
  cleaned_value *= -1 if value =~ /[\(\-]/
162
+ cleaned_value = -(cleaned_value) if options[:inverse]
162
163
  cleaned_value
163
164
  end
164
165
 
@@ -334,7 +335,15 @@ module Reckon
334
335
 
335
336
  def parse
336
337
  data = options[:string] || File.read(options[:file])
337
- @csv_data = (RUBY_VERSION =~ /^1\.9/ ? CSV : FasterCSV).parse(data.strip, :col_sep => options[:csv_separator] || ',')
338
+
339
+ if RUBY_VERSION =~ /^1\.9/ || RUBY_VERSION =~ /^2/
340
+ data = data.force_encoding(options[:encoding] || 'BINARY').encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')
341
+ csv_engine = CSV
342
+ else
343
+ csv_engine = FasterCSV
344
+ end
345
+
346
+ @csv_data = csv_engine.parse data.strip, :col_sep => options[:csv_separator] || ','
338
347
  csv_data.shift if options[:contains_header]
339
348
  csv_data
340
349
  end
@@ -353,6 +362,10 @@ module Reckon
353
362
  options[:verbose] = v
354
363
  end
355
364
 
365
+ opts.on("-i", "--inverse", "Use the negative of each amount") do |v|
366
+ options[:inverse] = v
367
+ end
368
+
356
369
  opts.on("-p", "--print-table", "Print out the parsed CSV in table form") do |p|
357
370
  options[:print_table] = p
358
371
  end
@@ -381,6 +394,10 @@ module Reckon
381
394
  options[:comma_separates_cents] = c
382
395
  end
383
396
 
397
+ opts.on("", "--encoding", "Specify an encoding for the CSV file") do |e|
398
+ options[:encoding] = e
399
+ end
400
+
384
401
  opts.on_tail("-h", "--help", "Show this message") do
385
402
  puts opts
386
403
  exit
data/reckon.gemspec CHANGED
@@ -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.3.4"
6
+ s.version = "0.3.5"
7
7
  s.authors = ["Andrew Cantino"]
8
8
  s.email = %q{andrew@iterationlabs.com}
9
9
  s.homepage = %q{https://github.com/cantino/reckon}
@@ -0,0 +1,24 @@
1
+ "Data","Dependencia Origem","Hist�rico","Data do Balancete","N�mero do documento","Valor",
2
+ "10/31/2012","","Saldo Anterior","","0","100.00",
3
+ "11/01/2012","0000-9","Transfer�ncia on line - 01/11 4885 256620-6 XXXXXXXXXXXXX","","224885000256620","100.00",
4
+ "11/01/2012","","Dep�sito COMPE - 033 0502 27588602104 XXXXXXXXXXXXXX","","101150","100.00",
5
+ "11/01/2012","","Proventos","","496774","1000.00",
6
+ "11/01/2012","","Benef�cio","","496775","100.00",
7
+ "11/01/2012","0000-0","Compra com Cart�o - 01/11 09:45 XXXXXXXXXXX","","135102","-1.00",
8
+ "11/01/2012","0000-0","Compra com Cart�o - 01/11 09:48 XXXXXXXXXXX","","235338","-10.00",
9
+ "11/01/2012","0000-0","Compra com Cart�o - 01/11 12:35 XXXXXXXX","","345329","-10.00",
10
+ "11/01/2012","0000-0","Compra com Cart�o - 01/11 23:57 XXXXXXXXXXXXXXXX","","686249","-10.00",
11
+ "11/01/2012","0000-0","Saque com cart�o - 01/11 13:17 XXXXXXXXXXXXXXXX","","11317296267021","-10.00",
12
+ "11/01/2012","","Pagto conta telefone - VIVO DF","","110101","-100.00",
13
+ "11/01/2012","","Cobran�a de I.O.F.","","391100701","-1.00",
14
+ "11/05/2012","0000-0","Compra com Cart�o - 02/11 16:57 XXXXXXXXXXXX","","161057","-10.00",
15
+ "11/05/2012","0000-0","Compra com Cart�o - 03/11 18:57 XXXXXXXXXXXXXXX","","168279","-10.00",
16
+ "11/05/2012","0000-0","Compra com Cart�o - 05/11 12:32 XXXXXXXXXXXXXXXXX","","245166","-10.00",
17
+ "11/05/2012","0000-0","Compra com Cart�o - 02/11 17:18 XXXXXXXXXXXXX","","262318","-1.00",
18
+ "11/05/2012","0000-0","Compra com Cart�o - 02/11 22:46 XXXXXXXXXXX","","382002","-100.00",
19
+ "11/05/2012","0000-0","Compra com Cart�o - 02/11 23:19 XXXXXXXXXXX","","683985","-1.00",
20
+ "11/05/2012","0000-0","Compra com Cart�o - 03/11 01:19 XXXXXXXXXXXXXXXX","","704772","-10.00",
21
+ "11/05/2012","0000-0","Compra com Cart�o - 03/11 11:08 XXXXXXXX","","840112","-1.00",
22
+ "11/05/2012","0000-0","Saque com cart�o - 05/11 19:24 XXXXXXXXXXXXXXXXX","","51924256267021","-10.00",
23
+ "11/05/2012","0000-0","Transfer�ncia on line - 05/11 4885 256620-6 XXXXXXXXXXXXX","","224885000256620","-100.00",
24
+ "11/05/2012","","Pagamento de T�tulo - XXXXXXXXXXXXXXXXXXX","","110501","-100.00",
@@ -21,8 +21,16 @@ describe Reckon::App do
21
21
  Reckon::App.settings[:testing].should be_true
22
22
  end
23
23
 
24
- it "should work with other separators" do
25
- Reckon::App.new(:string => "one;two\nthree;four", :csv_separator => ';').columns.should == [['one', 'three'], ['two', 'four']]
24
+ describe "parse" do
25
+ it "should work with foreign character encodings" do
26
+ app = Reckon::App.new(:file => File.expand_path(File.join(File.dirname(__FILE__), "..", "data_fixtures", "extratofake.csv")))
27
+ app.columns[0][0..2].should == ["Data", "10/31/2012", "11/01/2012"]
28
+ app.columns[2].first.should == "Hist?rico"
29
+ end
30
+
31
+ it "should work with other separators" do
32
+ Reckon::App.new(:string => "one;two\nthree;four", :csv_separator => ';').columns.should == [['one', 'three'], ['two', 'four']]
33
+ end
26
34
  end
27
35
 
28
36
  describe "columns" do
@@ -96,12 +104,18 @@ describe Reckon::App do
96
104
  @danish_kroner_nordea.money_for(4).should == -3452.90
97
105
  @danish_kroner_nordea.money_for(5).should == -655.00
98
106
  end
99
-
107
+
100
108
  it "should handle the comma_separates_cents option correctly" do
101
109
  european_csv = Reckon::App.new(:string => "$2,00;something\n1.025,67;something else", :csv_separator => ';', :comma_separates_cents => true)
102
110
  european_csv.money_for(0).should == 2.00
103
111
  european_csv.money_for(1).should == 1025.67
104
112
  end
113
+
114
+ it "should return negated values if the inverse option is passed" do
115
+ inversed_csv = Reckon::App.new(:string => INVERSED_CREDIT_CARD, :inverse => true)
116
+ inversed_csv.money_for(0).should == -30.00
117
+ inversed_csv.money_for(3).should == 500.00
118
+ end
105
119
  end
106
120
 
107
121
  describe "date_for" do
@@ -177,6 +191,25 @@ describe Reckon::App do
177
191
  CREDIT,2003/12/24,"Some Company vendorpymt PPD ID: 5KL3832735",$2105.00
178
192
  CSV
179
193
 
194
+ INVERSED_CREDIT_CARD = (<<-CSV).strip
195
+ 2013/01/17,2013/01/16,2013011702,DEBIT,2226,"VODAFONE PREPAY VISA M AUCKLAND NZL",30.00
196
+ 2013/01/18,2013/01/17,2013011801,DEBIT,2226,"WILSON PARKING AUCKLAND NZL",4.60
197
+ 2013/01/18,2013/01/17,2013011802,DEBIT,2226,"AUCKLAND TRANSPORT HENDERSON NZL",2.00
198
+ 2013/01/19,2013/01/19,2013011901,CREDIT,2226,"INTERNET PAYMENT RECEIVED ",-500.00
199
+ 2013/01/26,2013/01/23,2013012601,DEBIT,2226,"ITUNES NZ CORK IRL",64.99
200
+ 2013/01/26,2013/01/25,2013012602,DEBIT,2226,"VODAFONE FXFLNE BBND R NEWTON NZL",90.26
201
+ 2013/01/29,2013/01/29,2013012901,CREDIT,2101,"PAYMENT RECEIVED THANK YOU ",-27.75
202
+ 2013/01/30,2013/01/29,2013013001,DEBIT,2226,"AUCKLAND TRANSPORT HENDERSON NZL",3.50
203
+ 2013/02/05,2013/02/03,2013020501,DEBIT,2226,"Z BEACH RD AUCKLAND NZL",129.89
204
+ 2013/02/05,2013/02/03,2013020502,DEBIT,2226,"TOURNAMENT KHYBER PASS AUCKLAND NZL",8.00
205
+ 2013/02/05,2013/02/04,2013020503,DEBIT,2226,"VODAFONE PREPAY VISA M AUCKLAND NZL",30.00
206
+ 2013/02/08,2013/02/07,2013020801,DEBIT,2226,"AKLD TRANSPORT PARKING AUCKLAND NZL",2.50
207
+ 2013/02/08,2013/02/07,2013020802,DEBIT,2226,"AUCKLAND TRANSPORT HENDERSON NZL",3.50
208
+ 2013/02/12,2013/02/11,2013021201,DEBIT,2226,"AKLD TRANSPORT PARKING AUCKLAND NZL",1.50
209
+ 2013/02/17,2013/02/17,2013021701,CREDIT,2226,"INTERNET PAYMENT RECEIVED ",-12.00
210
+ 2013/02/17,2013/02/17,2013021702,CREDIT,2226,"INTERNET PAYMENT RECEIVED ",-18.00
211
+ CSV
212
+
180
213
  TWO_MONEY_COLUMNS_BANK = (<<-CSV).strip
181
214
  4/1/2008,Check - 0000000122,122,-$76.00,"","$1,750.06"
182
215
  3/28/2008,BLARG R SH 456930,"","",+$327.49,"$1,826.06"
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.3.4
4
+ version: 0.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-16 00:00:00.000000000 Z
12
+ date: 2013-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -103,6 +103,7 @@ files:
103
103
  - .document
104
104
  - .gitignore
105
105
  - .rvmrc
106
+ - CHANGES.md
106
107
  - Gemfile
107
108
  - Gemfile.lock
108
109
  - LICENSE
@@ -114,6 +115,7 @@ files:
114
115
  - lib/reckon/app.rb
115
116
  - lib/reckon/ledger_parser.rb
116
117
  - reckon.gemspec
118
+ - spec/data_fixtures/extratofake.csv
117
119
  - spec/reckon/app_spec.rb
118
120
  - spec/reckon/ledger_parser_spec.rb
119
121
  - spec/spec.opts
@@ -144,6 +146,7 @@ specification_version: 3
144
146
  summary: Utility for interactively converting and labeling CSV files for the Ledger
145
147
  accounting tool.
146
148
  test_files:
149
+ - spec/data_fixtures/extratofake.csv
147
150
  - spec/reckon/app_spec.rb
148
151
  - spec/reckon/ledger_parser_spec.rb
149
152
  - spec/spec.opts