reckon 0.5.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +50 -0
  3. data/.gitignore +3 -0
  4. data/.ruby-version +1 -1
  5. data/CHANGELOG.md +77 -8
  6. data/Gemfile.lock +1 -5
  7. data/README.md +74 -21
  8. data/Rakefile +17 -1
  9. data/bin/build-new-version.sh +26 -0
  10. data/bin/reckon +6 -1
  11. data/lib/reckon.rb +2 -2
  12. data/lib/reckon/app.rb +140 -194
  13. data/lib/reckon/csv_parser.rb +8 -8
  14. data/lib/reckon/date_column.rb +10 -0
  15. data/lib/reckon/ledger_parser.rb +5 -1
  16. data/lib/reckon/money.rb +48 -48
  17. data/lib/reckon/options.rb +147 -0
  18. data/lib/reckon/version.rb +1 -1
  19. data/reckon.gemspec +1 -2
  20. data/spec/integration/another_bank_example/input.csv +9 -0
  21. data/spec/integration/another_bank_example/output.ledger +36 -0
  22. data/spec/integration/another_bank_example/test_args +1 -0
  23. data/spec/integration/austrian_example/input.csv +13 -0
  24. data/spec/integration/austrian_example/output.ledger +52 -0
  25. data/spec/integration/austrian_example/test_args +2 -0
  26. data/spec/integration/bom_utf8_file/input.csv +3 -0
  27. data/spec/integration/bom_utf8_file/output.ledger +4 -0
  28. data/spec/integration/bom_utf8_file/test_args +3 -0
  29. data/spec/integration/broker_canada_example/input.csv +12 -0
  30. data/spec/integration/broker_canada_example/output.ledger +48 -0
  31. data/spec/integration/broker_canada_example/test_args +1 -0
  32. data/spec/integration/chase/account_tokens_and_regex/output.ledger +36 -0
  33. data/spec/integration/chase/account_tokens_and_regex/test_args +2 -0
  34. data/spec/integration/chase/account_tokens_and_regex/tokens.yml +16 -0
  35. data/spec/integration/chase/default_account_names/output.ledger +36 -0
  36. data/spec/integration/chase/default_account_names/test_args +3 -0
  37. data/spec/integration/chase/input.csv +9 -0
  38. data/spec/integration/chase/learn_from_existing/learn.ledger +7 -0
  39. data/spec/integration/chase/learn_from_existing/output.ledger +36 -0
  40. data/spec/integration/chase/learn_from_existing/test_args +1 -0
  41. data/spec/integration/chase/simple/output.ledger +36 -0
  42. data/spec/integration/chase/simple/test_args +1 -0
  43. data/spec/integration/danish_kroner_nordea_example/input.csv +6 -0
  44. data/spec/integration/danish_kroner_nordea_example/output.ledger +24 -0
  45. data/spec/integration/danish_kroner_nordea_example/test_args +1 -0
  46. data/spec/integration/english_date_example/input.csv +3 -0
  47. data/spec/integration/english_date_example/output.ledger +12 -0
  48. data/spec/integration/english_date_example/test_args +1 -0
  49. data/spec/integration/extratofake/input.csv +24 -0
  50. data/spec/integration/extratofake/output.ledger +92 -0
  51. data/spec/integration/extratofake/test_args +1 -0
  52. data/spec/integration/french_example/input.csv +9 -0
  53. data/spec/integration/french_example/output.ledger +36 -0
  54. data/spec/integration/french_example/test_args +2 -0
  55. data/spec/integration/german_date_example/input.csv +3 -0
  56. data/spec/integration/german_date_example/output.ledger +12 -0
  57. data/spec/integration/german_date_example/test_args +1 -0
  58. data/spec/integration/harder_date_example/input.csv +5 -0
  59. data/spec/integration/harder_date_example/output.ledger +20 -0
  60. data/spec/integration/harder_date_example/test_args +1 -0
  61. data/spec/integration/ing/input.csv +3 -0
  62. data/spec/integration/ing/output.ledger +12 -0
  63. data/spec/integration/ing/test_args +1 -0
  64. data/spec/integration/intuit_mint_example/input.csv +7 -0
  65. data/spec/integration/intuit_mint_example/output.ledger +28 -0
  66. data/spec/integration/intuit_mint_example/test_args +1 -0
  67. data/spec/integration/invalid_header_example/input.csv +6 -0
  68. data/spec/integration/invalid_header_example/output.ledger +8 -0
  69. data/spec/integration/invalid_header_example/test_args +1 -0
  70. data/spec/integration/inversed_credit_card/input.csv +16 -0
  71. data/spec/integration/inversed_credit_card/output.ledger +64 -0
  72. data/spec/integration/inversed_credit_card/test_args +1 -0
  73. data/spec/integration/nationwide/input.csv +4 -0
  74. data/spec/integration/nationwide/output.ledger +16 -0
  75. data/spec/integration/nationwide/test_args +1 -0
  76. data/spec/integration/regression/issue_51_account_tokens/input.csv +8 -0
  77. data/spec/integration/regression/issue_51_account_tokens/output.ledger +32 -0
  78. data/spec/integration/regression/issue_51_account_tokens/test_args +4 -0
  79. data/spec/integration/regression/issue_51_account_tokens/tokens.yml +9 -0
  80. data/spec/integration/regression/issue_64_date_column/input.csv +3 -0
  81. data/spec/integration/regression/issue_64_date_column/output.ledger +8 -0
  82. data/spec/integration/regression/issue_64_date_column/test_args +1 -0
  83. data/spec/integration/regression/issue_73_account_token_matching/input.csv +2 -0
  84. data/spec/integration/regression/issue_73_account_token_matching/output.ledger +4 -0
  85. data/spec/integration/regression/issue_73_account_token_matching/test_args +6 -0
  86. data/spec/integration/regression/issue_73_account_token_matching/tokens.yml +8 -0
  87. data/spec/integration/regression/issue_85_date_example/input.csv +2 -0
  88. data/spec/integration/regression/issue_85_date_example/output.ledger +8 -0
  89. data/spec/integration/regression/issue_85_date_example/test_args +1 -0
  90. data/spec/integration/spanish_date_example/input.csv +3 -0
  91. data/spec/integration/spanish_date_example/output.ledger +12 -0
  92. data/spec/integration/spanish_date_example/test_args +1 -0
  93. data/spec/integration/suntrust/input.csv +7 -0
  94. data/spec/integration/suntrust/output.ledger +28 -0
  95. data/spec/integration/suntrust/test_args +1 -0
  96. data/spec/integration/test.sh +83 -0
  97. data/spec/integration/test_money_column/input.csv +3 -0
  98. data/spec/integration/test_money_column/output.ledger +8 -0
  99. data/spec/integration/test_money_column/test_args +1 -0
  100. data/spec/integration/two_money_columns/input.csv +5 -0
  101. data/spec/integration/two_money_columns/output.ledger +20 -0
  102. data/spec/integration/two_money_columns/test_args +1 -0
  103. data/spec/integration/yyyymmdd_date_example/input.csv +1 -0
  104. data/spec/integration/yyyymmdd_date_example/output.ledger +4 -0
  105. data/spec/integration/yyyymmdd_date_example/test_args +1 -0
  106. data/spec/reckon/app_spec.rb +25 -7
  107. data/spec/reckon/csv_parser_spec.rb +5 -0
  108. data/spec/reckon/ledger_parser_spec.rb +19 -4
  109. data/spec/reckon/money_column_spec.rb +24 -24
  110. data/spec/reckon/money_spec.rb +13 -32
  111. data/spec/reckon/options_spec.rb +17 -0
  112. data/spec/spec_helper.rb +6 -1
  113. metadata +98 -59
  114. data/.travis.yml +0 -13
@@ -0,0 +1,4 @@
1
+ -f input.csv --unattended --account Assets:Chequing \
2
+ --ignore-columns 5 \
3
+ --account-tokens tokens.yml
4
+
@@ -0,0 +1,9 @@
1
+ Expenses:
2
+ Dining:
3
+ Coffee:
4
+ - 'STARBUCKS'
5
+ - 'TIM HORTON'
6
+ Resturant:
7
+ - 'WENDY''S'
8
+ - 'SUBWAY'
9
+ - 'BARAKAT'
@@ -0,0 +1,3 @@
1
+ "Date","Note","Amount"
2
+ "2012/3/22","DEPOSIT","50.00"
3
+ "2012/3/23","TRANSFER TO SAVINGS","-10.00"
@@ -0,0 +1,8 @@
1
+ 2012-03-22 DEPOSIT
2
+ Assets:Bank:Checking $50.00
3
+ Income:Unknown
4
+
5
+ 2012-03-23 TRANSFER TO SAVINGS
6
+ Expenses:Unknown
7
+ Assets:Bank:Checking -$10.00
8
+
@@ -0,0 +1 @@
1
+ -f input.csv --unattended --account Assets:Bank:Checking
@@ -0,0 +1,2 @@
1
+ Transaction Date,Description,Amount,Category
2
+ 07/06/2017,TRIPLE T CAR WASH CHAMPAIGN IL,$27.00,Automotive
@@ -0,0 +1,4 @@
1
+ 2017-07-06 TRIPLE T CAR WASH CHAMPAIGN IL
2
+ Liabilities:Credit Cards:Visa $27.00
3
+ Expenses:Automotive:Car Wash
4
+
@@ -0,0 +1,6 @@
1
+ -f input.csv --unattended --account 'Liabilities:Credit Cards:Visa' \
2
+ --contains-header 1 \
3
+ --ignore-columns 4 \
4
+ --date-format %m/%d/%Y \
5
+ --account-tokens tokens.yml
6
+
@@ -0,0 +1,8 @@
1
+ Expenses:
2
+ Automotive:
3
+ Car Wash:
4
+ - 'TRIPLE T CAR WASH CHAMPAIGN IL'
5
+ - "BIG T's CAR WASH"
6
+ Maintenance:
7
+ - 'Autozone'
8
+ - "O'Reillys auto parts"
@@ -0,0 +1,2 @@
1
+ Visa, 4514010000000000, 2020-02-20, , GOJEK SINGAPORE, 8.10 SGD @ .976500000000, -7.91, D
2
+ Visa, 4514010000000000, 2020-02-20, , GOJEK SINGAPORE, 6.00 SGD @ .976600000000, -5.86, D
@@ -0,0 +1,8 @@
1
+ 2020-02-20 Visa; 4514010000000000; GOJEK SINGAPORE; 6.00 SGD @ .976600000000; D
2
+ Expenses:Unknown
3
+ Assets:Bank:Checking -$5.86
4
+
5
+ 2020-02-20 Visa; 4514010000000000; GOJEK SINGAPORE; 8.10 SGD @ .976500000000; D
6
+ Expenses:Unknown
7
+ Assets:Bank:Checking -$7.91
8
+
@@ -0,0 +1 @@
1
+ -f input.csv --unattended --account Assets:Bank:Checking
@@ -0,0 +1,3 @@
1
+ 02/12/2009,Check - 0000000122,122,-$76.00,"","$1,750.06"
2
+ 02/12/2009,BLARG R SH 456930,"","",+$327.49,"$1,826.06"
3
+ 02/12/2009,Check - 0000000112,112,-$800.00,"","$1,498.57"
@@ -0,0 +1,12 @@
1
+ 2009-12-02 BLARG R SH 456930; $1,826.06
2
+ Assets:Bank:Checking $327.49
3
+ Income:Unknown
4
+
5
+ 2009-12-02 Check - 0000000122; 122; $1,750.06
6
+ Income:Unknown
7
+ Assets:Bank:Checking -$76.00
8
+
9
+ 2009-12-02 Check - 0000000112; 112; $1,498.57
10
+ Income:Unknown
11
+ Assets:Bank:Checking -$800.00
12
+
@@ -0,0 +1 @@
1
+ -f input.csv --unattended --account Assets:Bank:Checking --date-format '%d/%m/%Y'
@@ -0,0 +1,7 @@
1
+ 11/01/2014,0, Deposit,0,500.00,500.00
2
+ 11/02/2014,101,Check,100.00,0,400.00
3
+ 11/03/2014,102,Check,100.00,0,300.00
4
+ 11/04/2014,103,Check,100.00,0,200.00
5
+ 11/05/2014,104,Check,100.00,0,100.00
6
+ 11/06/2014,105,Check,100.00,0,0.00
7
+ 11/17/2014,0, Deposit,0,700.00,700.00
@@ -0,0 +1,28 @@
1
+ 2014-11-01 0; Deposit; 500.00
2
+ Assets:Bank:Checking $500.00
3
+ Income:Unknown
4
+
5
+ 2014-11-02 101; Check; 400.00
6
+ Expenses:Unknown
7
+ Assets:Bank:Checking -$100.00
8
+
9
+ 2014-11-03 102; Check; 300.00
10
+ Expenses:Unknown
11
+ Assets:Bank:Checking -$100.00
12
+
13
+ 2014-11-04 103; Check; 200.00
14
+ Expenses:Unknown
15
+ Assets:Bank:Checking -$100.00
16
+
17
+ 2014-11-05 104; Check; 100.00
18
+ Expenses:Unknown
19
+ Assets:Bank:Checking -$100.00
20
+
21
+ 2014-11-06 105; Check; 0.00
22
+ Expenses:Unknown
23
+ Assets:Bank:Checking -$100.00
24
+
25
+ 2014-11-17 0; Deposit; 700.00
26
+ Assets:Bank:Checking $700.00
27
+ Income:Unknown
28
+
@@ -0,0 +1 @@
1
+ -f input.csv --unattended --account Assets:Bank:Checking
@@ -0,0 +1,83 @@
1
+ #!/bin/bash
2
+
3
+ # set -x
4
+
5
+ set -Euo pipefail
6
+
7
+ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
8
+ TEST_DIFF=""
9
+ OUTPUT=""
10
+ RECKON_CMD="env RUBYLIB=$SCRIPT_DIR/../../lib:$RUBYLIB reckon -v"
11
+ export PATH="$SCRIPT_DIR/../../bin:$PATH"
12
+
13
+ main () {
14
+ trap test_fail EXIT
15
+
16
+ if [[ $# -eq 1 ]]; then
17
+ TESTS=$1/test_args
18
+ else
19
+ TESTS=$(find "$SCRIPT_DIR" -name 'test_args')
20
+ fi
21
+
22
+ echo > test.log
23
+
24
+ for t in $TESTS; do
25
+ OUTPUT_FILE=$(mktemp)
26
+ TEST_DIR=$(dirname "$t")
27
+ pushd "$TEST_DIR" >/dev/null || exit 1
28
+ echo "$TEST_DIR Running..."
29
+ TEST_CMD="$RECKON_CMD -o $OUTPUT_FILE $(cat test_args)"
30
+ TEST_LOG=$(eval "$TEST_CMD" 2>&1)
31
+ ERROR=0
32
+
33
+ compare_output "$OUTPUT_FILE"
34
+
35
+ popd >/dev/null || exit 1
36
+ # have to save output after popd
37
+ echo -e "\n\n======>$TEST_DIR" >> test.log
38
+ echo -e "TEST_CMD\n$TEST_LOG" >> test.log
39
+
40
+ if [[ $ERROR -ne 0 ]]; then
41
+ exit 1
42
+ fi
43
+ done
44
+ }
45
+
46
+ test_fail () {
47
+ STATUS=$?
48
+ if [[ $STATUS -ne 0 ]]; then
49
+ echo -e "FAILED!!!\n$TEST_DIFF\nTest output saved to $OUTPUT_FILE\n"
50
+ exit $STATUS
51
+ fi
52
+ }
53
+
54
+ compare_output_for () {
55
+ OUTPUT_FILE=$1
56
+ LEDGER=$2
57
+
58
+ TEST_DIFF=$(diff -u <($LEDGER -f output.ledger r --date-format %F 2>&1) <($LEDGER -f "$OUTPUT_FILE" r --date-format %F 2>&1) )
59
+
60
+ # ${#} is character length, test that there was no output from diff
61
+ if [ ${#TEST_DIFF} -eq 0 ]; then
62
+ return 0
63
+ else
64
+ return 1
65
+ fi
66
+ }
67
+
68
+ compare_output () {
69
+ OUTPUT_FILE=$1
70
+
71
+ for n in {ledger,hledger}; do
72
+ echo -n " - $n..."
73
+ if compare_output_for "$OUTPUT_FILE" "$n"; then
74
+ echo "SUCCESS!"
75
+ else
76
+ echo "FAILED!"
77
+ ERROR=1
78
+ return 0
79
+ fi
80
+ done
81
+ }
82
+
83
+ main "$@"
@@ -0,0 +1,3 @@
1
+ "Date","Note","Amount"
2
+ "2012/3/22","DEPOSIT","50.00"
3
+ "2012/3/23","TRANSFER TO SAVINGS","-10.00"
@@ -0,0 +1,8 @@
1
+ 2012-03-22 DEPOSIT
2
+ Assets:Bank:Checking $50.00
3
+ Income:Unknown
4
+
5
+ 2012-03-23 TRANSFER TO SAVINGS
6
+ Expenses:Unknown
7
+ Assets:Bank:Checking -$10.00
8
+
@@ -0,0 +1 @@
1
+ -f input.csv --unattended --account Assets:Bank:Checking
@@ -0,0 +1,5 @@
1
+ 4/1/2008,Check - 0000000122,122,-$76.00,"","$1,750.06"
2
+ 3/28/2008,BLARG R SH 456930,"","",+$327.49,"$1,826.06"
3
+ 3/27/2008,Check - 0000000112,112,-$800.00,"","$1,498.57"
4
+ 3/26/2008,Check - 0000000251,251,-$88.55,"","$1,298.57"
5
+ 3/26/2008,Check - 0000000251,251,"","+$88.55","$1,298.57"
@@ -0,0 +1,20 @@
1
+ 2008-03-26 Check - 0000000251; 251; $1,298.57
2
+ Assets:Bank:Checking $88.55
3
+ Income:Unknown
4
+
5
+ 2008-03-26 Check - 0000000251; 251; $1,298.57
6
+ Income:Unknown
7
+ Assets:Bank:Checking -$88.55
8
+
9
+ 2008-03-27 Check - 0000000112; 112; $1,498.57
10
+ Income:Unknown
11
+ Assets:Bank:Checking -$800.00
12
+
13
+ 2008-03-28 BLARG R SH 456930; $1,826.06
14
+ Assets:Bank:Checking $327.49
15
+ Income:Unknown
16
+
17
+ 2008-04-01 Check - 0000000122; 122; $1,750.06
18
+ Income:Unknown
19
+ Assets:Bank:Checking -$76.00
20
+
@@ -0,0 +1 @@
1
+ -f input.csv --unattended --account Assets:Bank:Checking
@@ -0,0 +1 @@
1
+ DEBIT,20121231,"ODESK***BAL-27DEC12 650-12345 CA 12/28",-123.45
@@ -0,0 +1,4 @@
1
+ 2012-12-31 DEBIT; ODESK***BAL-27DEC12 650-12345 CA 12/28
2
+ Expenses:Unknown
3
+ Assets:Bank:Checking -$123.45
4
+
@@ -0,0 +1 @@
1
+ -f input.csv --unattended --account Assets:Bank:Checking
@@ -8,7 +8,7 @@ describe Reckon::App do
8
8
  context 'with chase csv input' do
9
9
  before do
10
10
  @chase = Reckon::App.new(string: BANK_CSV)
11
- @chase.learn_from(BANK_LEDGER)
11
+ @chase.learn_from_ledger(BANK_LEDGER)
12
12
  @rows = []
13
13
  @chase.each_row_backwards { |row| @rows.push(row) }
14
14
  end
@@ -19,7 +19,7 @@ describe Reckon::App do
19
19
  @rows[0][:pretty_money].should == " $2105.00"
20
20
  @rows[0][:description].should == "CREDIT; Some Company vendorpymt PPD ID: 5KL3832735"
21
21
  @rows[1][:pretty_date].should == "2009-12-11"
22
- @rows[1][:pretty_money].should == "-$116.22"
22
+ @rows[1][:pretty_money].should == " $116.22"
23
23
  @rows[1][:description].should == "CREDIT; PAYPAL TRANSFER PPD ID: PAYPALSDSL"
24
24
  end
25
25
  end
@@ -37,14 +37,16 @@ describe Reckon::App do
37
37
 
38
38
  context 'unattended mode with chase csv input' do
39
39
  let(:output_file) { StringIO.new }
40
- let(:chase) {
40
+ let(:chase) do
41
41
  Reckon::App.new(
42
42
  string: BANK_CSV,
43
43
  unattended: true,
44
44
  output_file: output_file,
45
- bank_account: 'Assets:Bank:Checking'
45
+ bank_account: 'Assets:Bank:Checking',
46
+ default_into_account: 'Expenses:Unknown',
47
+ default_outof_account: 'Income:Unknown',
46
48
  )
47
- }
49
+ end
48
50
 
49
51
  describe 'walk backwards' do
50
52
  it 'should assign Income:Unknown and Expenses:Unknown by default' do
@@ -68,7 +70,7 @@ describe Reckon::App do
68
70
  end
69
71
 
70
72
  it 'should learn from a ledger file' do
71
- chase.learn_from( BANK_LEDGER )
73
+ chase.learn_from_ledger(BANK_LEDGER)
72
74
  chase.walk_backwards
73
75
  output_file.string.scan('Expenses:Books').count.should == 1
74
76
  end
@@ -86,6 +88,22 @@ describe Reckon::App do
86
88
  expect(output_file.string.scan('Expenses:Websites').count).to eq(2)
87
89
  end
88
90
  end
91
+
92
+ it 'should fail-on-unknown-account' do
93
+ chase = Reckon::App.new(
94
+ string: BANK_CSV,
95
+ unattended: true,
96
+ output_file: output_file,
97
+ bank_account: 'Assets:Bank:Checking',
98
+ default_into_account: 'Expenses:Unknown',
99
+ default_outof_account: 'Income:Unknown',
100
+ fail_on_unknown_account: true
101
+ )
102
+
103
+ expect { chase.walk_backwards }.to(
104
+ raise_error(RuntimeError, /Couldn't find any matches/)
105
+ )
106
+ end
89
107
  end
90
108
 
91
109
  context "Issue #73 - regression test" do
@@ -146,7 +164,7 @@ describe Reckon::App do
146
164
  CREDIT,20091223120000[0:GMT],"Blarg BLARG REVENUE PPD ID: 00jah78563",1558.52
147
165
  DEBIT,20091221120000[0:GMT],"WEBSITE-BALANCE-17DEC09 12 12/17WEBSITE-BAL",-12.23
148
166
  DEBIT,20091214120000[0:GMT],"WEBSITE-BALANCE-10DEC09 12 12/10WEBSITE-BAL",-20.96
149
- CREDIT,20091211120000[0:GMT],"PAYPAL TRANSFER PPD ID: PAYPALSDSL",-116.22
167
+ CREDIT,20091211120000[0:GMT],"PAYPAL TRANSFER PPD ID: PAYPALSDSL",116.22
150
168
  CREDIT,20091210120000[0:GMT],"Some Company vendorpymt PPD ID: 5KL3832735",2105.00
151
169
  CSV
152
170
 
@@ -232,6 +232,11 @@ describe Reckon::CSVParser do
232
232
  parser = Reckon::CSVParser.new(:string => '01/09/2015,05354 SUBWAY,8.19,,',:date_format => '%d/%m/%Y')
233
233
  parser.description_for(0).should == '05354 SUBWAY'
234
234
  end
235
+
236
+ it "should handle nil description" do
237
+ parser = Reckon::CSVParser.new(string: '2015-09-01,test,3.99')
238
+ expect(parser.description_for(1)).to eq("")
239
+ end
235
240
  end
236
241
 
237
242
  describe "pretty_money_for" do
@@ -20,12 +20,13 @@ describe Reckon::LedgerParser do
20
20
  formats = ["%Y/%m/%d", "%Y-%m-%d"]
21
21
  types = [' ! ', ' * ', ' ']
22
22
  delimiters = [" ", "\t", "\t\t"]
23
+ comment_chars = ';#%*|'
23
24
  currency_delimiters = delimiters + ['']
24
25
  currencies = ['', '$', '£']
25
26
  property_of do
26
27
  Rantly do
27
28
  description = Proc.new do
28
- sized(15){string}.tr(%q{'`:*\\},'').gsub(/\s+/, ' ').gsub(/^[!;<\[( ]+/, '')
29
+ sized(15){string}.tr(%q{'`:*\\},'').gsub(/\s+/, ' ').gsub(/^[!;<\[( #{comment_chars}]+/, '')
29
30
  end
30
31
  currency = choose(*currencies) # to be consistent within the transaction
31
32
  single_line_comments = ";#|%*".split('').map { |n| "#{n} #{call(description)}" }
@@ -56,11 +57,12 @@ describe Reckon::LedgerParser do
56
57
  filter_format = lambda { |n| [n['date'], n['desc'], n['name'], sprintf("%.02f", n['amount'])] }
57
58
  headers = %w[date code desc name currency amount type commend]
58
59
  safe_s = Shellwords.escape(s)
59
- ledger_csv = `echo #{safe_s} | ledger csv --date-format '%Y-%m-%d' -f - `
60
- ledger_parser_csv = Reckon::LedgerParser.new(s, date_format: '%Y/%m/%d').to_csv.join("\n")
61
60
 
61
+ lp_csv = Reckon::LedgerParser.new(s, date_format: '%Y/%m/%d').to_csv.join("\n")
62
+ actual = CSV.parse(lp_csv, headers: headers).map(&filter_format)
63
+
64
+ ledger_csv = `echo #{safe_s} | ledger csv --date-format '%Y/%m/%d' -f - `
62
65
  expected = CSV.parse(ledger_csv.gsub('\"', '""'), headers: headers).map(&filter_format)
63
- actual = CSV.parse(ledger_parser_csv, headers: headers).map(&filter_format)
64
66
  expected.length.times do |i|
65
67
  expect(actual[i]).to eq(expected[i])
66
68
  end
@@ -87,6 +89,19 @@ HERE
87
89
 
88
90
  end
89
91
 
92
+ it 'should transaction comments' do
93
+ ledger = <<HERE
94
+ 2020-03-27 AMZN Mktp USX999H3203; Shopping; Sale
95
+ Expenses:Household $82.77
96
+ Liabilities:ChaseSapphire -$81.77
97
+ # END FINANCE SCRIPT OUTPUT Thu 02 Apr 2020 12:05:54 PM EDT
98
+ HERE
99
+ l = Reckon::LedgerParser.new(ledger)
100
+ expect(l.entries.first[:accounts].map { |n| n[:name] }).to eq(['Expenses:Household', 'Liabilities:ChaseSapphire'])
101
+ expect(l.entries.first[:accounts].size).to eq(2)
102
+ expect(l.entries.length).to eq(1)
103
+ end
104
+
90
105
  it "should ignore non-standard entries" do
91
106
  @ledger.entries.length.should == 7
92
107
  end
@@ -8,13 +8,13 @@ require 'reckon'
8
8
  describe Reckon::MoneyColumn do
9
9
  describe "initialize" do
10
10
  it "should convert strings into Money" do
11
- Reckon::MoneyColumn.new( ["1.00", "-2.00"] ).should == [
11
+ Reckon::MoneyColumn.new( ["1.00", "-2.00"] ).should == [
12
12
  Reckon::Money.new( 1.00 ), Reckon::Money.new( -2.00 ) ]
13
13
  end
14
14
  it "should convert empty string into nil" do
15
- Reckon::MoneyColumn.new( ["1.00", ""] ).should == [
15
+ Reckon::MoneyColumn.new( ["1.00", ""] ).should == [
16
16
  Reckon::Money.new( 1.00 ), nil ]
17
- Reckon::MoneyColumn.new( ["", "-2.00"] ).should == [
17
+ Reckon::MoneyColumn.new( ["", "-2.00"] ).should == [
18
18
  nil, Reckon::Money.new( -2.00 ) ]
19
19
  end
20
20
  end
@@ -32,33 +32,33 @@ describe Reckon::MoneyColumn do
32
32
 
33
33
  describe "merge" do
34
34
  it "should merge two columns" do
35
- Reckon::MoneyColumn.new( ["1.00", ""] ).merge!(
36
- Reckon::MoneyColumn.new( ["", "-2.00"] ) ).should == [
37
- Reckon::Money.new( 1.00 ), Reckon::Money.new( -2.00 ) ]
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
35
+ m1 = Reckon::MoneyColumn.new(["1.00", ""])
36
+ m2 = Reckon::MoneyColumn.new(["", "-2.00"])
37
+ expect(m1.merge!(m2)).to(
38
+ eq([Reckon::Money.new(1.00), Reckon::Money.new(-2.00)])
39
+ )
40
+
41
+ m1 = Reckon::MoneyColumn.new(["1.00", "0"])
42
+ m2 = Reckon::MoneyColumn.new(["0", "-2.00"])
43
+ expect(m1.merge!(m2)).to(
44
+ eq([Reckon::Money.new(1.00), Reckon::Money.new(-2.00)])
45
+ )
46
+ end
48
47
 
49
48
  it "should return nil if columns cannot be merged" do
50
- Reckon::MoneyColumn.new( ["1.00", ""] ).merge!(
51
- Reckon::MoneyColumn.new( ["1.00", "-2.00"] ) ).should == nil
49
+ m1 = Reckon::MoneyColumn.new(["1.00", ""])
50
+ m2 = Reckon::MoneyColumn.new(["1.00", "-2.00"])
51
+ expect(m1.merge!(m2)).to eq([Reckon::Money.new(0), Reckon::Money.new(-2)])
52
52
 
53
- Reckon::MoneyColumn.new( ["From1", "Names"] ).merge!(
54
- Reckon::MoneyColumn.new( ["Acc", "NL28 INGB 1200 3244 16,21817"] ) ).should == nil
53
+ m1 = Reckon::MoneyColumn.new(["From1", "Names"])
54
+ m2 = Reckon::MoneyColumn.new(["Acc", "NL28 INGB 1200 3244 16,21817"])
55
+ expect(m1.merge!(m2)).to eq([Reckon::Money.new(-1), Reckon::Money.new("NL28 INGB 1200 3244 16,21817")])
55
56
  end
56
57
 
57
58
  it "should invert first column if both positive" do
58
- Reckon::MoneyColumn.new( ["1.00", ""] ).merge!(
59
- Reckon::MoneyColumn.new( ["", "2.00"] ) ).should == [
60
- Reckon::Money.new( -1.00 ), Reckon::Money.new( 2.00 ) ]
59
+ expect(
60
+ Reckon::MoneyColumn.new(["1.00", ""]).merge!(Reckon::MoneyColumn.new( ["", "2.00"]))
61
+ ).to eq([Reckon::Money.new(-1.00), Reckon::Money.new(2.00)])
61
62
  end
62
63
  end
63
64
  end
64
-