reckon 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -0
- data/.rubocop.yml +20 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +2 -2
- data/bin/build-new-version.sh +3 -2
- data/bin/reckon +1 -1
- data/lib/reckon/app.rb +27 -24
- data/lib/reckon/beancount_parser.rb +150 -0
- data/lib/reckon/cosine_similarity.rb +0 -1
- data/lib/reckon/csv_parser.rb +73 -37
- data/lib/reckon/date_column.rb +18 -7
- data/lib/reckon/ledger_parser.rb +23 -15
- data/lib/reckon/money.rb +18 -16
- data/lib/reckon/options.rb +44 -19
- data/lib/reckon/version.rb +1 -1
- data/lib/reckon.rb +1 -0
- data/spec/cosine_training_and_test.rb +1 -1
- data/spec/data_fixtures/multi-line-field.csv +5 -0
- data/spec/integration/invalid_header_example/output.ledger +6 -7
- data/spec/integration/invalid_header_example/test_args +1 -1
- data/spec/integration/tab_delimited_file/input.csv +2 -0
- data/spec/integration/tab_delimited_file/output.ledger +8 -0
- data/spec/integration/tab_delimited_file/test_args +1 -0
- data/spec/reckon/csv_parser_spec.rb +85 -26
- data/spec/reckon/date_column_spec.rb +6 -0
- data/spec/reckon/ledger_parser_spec.rb +25 -23
- data/spec/reckon/options_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- metadata +8 -2
@@ -8,10 +8,12 @@ require 'pp'
|
|
8
8
|
require 'rantly'
|
9
9
|
require 'rantly/rspec_extensions'
|
10
10
|
require 'shellwords'
|
11
|
+
require 'stringio'
|
11
12
|
|
12
13
|
describe Reckon::LedgerParser do
|
13
14
|
before do
|
14
|
-
@ledger = Reckon::LedgerParser.new(
|
15
|
+
@ledger = Reckon::LedgerParser.new(date_format: '%Y/%m/%d')
|
16
|
+
@entries = @ledger.parse(StringIO.new(EXAMPLE_LEDGER))
|
15
17
|
end
|
16
18
|
|
17
19
|
describe "parse" do
|
@@ -58,7 +60,7 @@ describe Reckon::LedgerParser do
|
|
58
60
|
headers = %w[date code desc name currency amount type commend]
|
59
61
|
safe_s = Shellwords.escape(s)
|
60
62
|
|
61
|
-
lp_csv = Reckon::LedgerParser.new(
|
63
|
+
lp_csv = Reckon::LedgerParser.new(date_format: '%Y/%m/%d').to_csv(StringIO.new(s)).join("\n")
|
62
64
|
actual = CSV.parse(lp_csv, headers: headers).map(&filter_format)
|
63
65
|
|
64
66
|
ledger_csv = `echo #{safe_s} | ledger csv --date-format '%Y/%m/%d' -f - `
|
@@ -83,9 +85,9 @@ comment
|
|
83
85
|
|
84
86
|
end comment
|
85
87
|
HERE
|
86
|
-
|
87
|
-
expect(
|
88
|
-
expect(
|
88
|
+
entries = Reckon::LedgerParser.new.parse(StringIO.new(ledger))
|
89
|
+
expect(entries.length).to eq(1)
|
90
|
+
expect(entries.first[:desc]).to eq('Dinner should show up')
|
89
91
|
|
90
92
|
end
|
91
93
|
|
@@ -96,30 +98,30 @@ HERE
|
|
96
98
|
Liabilities:ChaseSapphire -$81.77
|
97
99
|
# END FINANCE SCRIPT OUTPUT Thu 02 Apr 2020 12:05:54 PM EDT
|
98
100
|
HERE
|
99
|
-
|
100
|
-
expect(
|
101
|
-
expect(
|
102
|
-
expect(
|
101
|
+
entries = Reckon::LedgerParser.new.parse(StringIO.new(ledger))
|
102
|
+
expect(entries.first[:accounts].map { |n| n[:name] }).to eq(['Expenses:Household', 'Liabilities:ChaseSapphire'])
|
103
|
+
expect(entries.first[:accounts].size).to eq(2)
|
104
|
+
expect(entries.length).to eq(1)
|
103
105
|
end
|
104
106
|
|
105
107
|
it "should ignore non-standard entries" do
|
106
|
-
@
|
108
|
+
@entries.length.should == 7
|
107
109
|
end
|
108
110
|
|
109
111
|
it "should parse entries correctly" do
|
110
|
-
@
|
111
|
-
@
|
112
|
-
@
|
113
|
-
@
|
114
|
-
@
|
115
|
-
@
|
116
|
-
|
117
|
-
@
|
118
|
-
@
|
119
|
-
@
|
120
|
-
@
|
121
|
-
@
|
122
|
-
@
|
112
|
+
@entries.first[:desc].should == "Checking balance"
|
113
|
+
@entries.first[:date].should == Date.parse("2004-05-01")
|
114
|
+
@entries.first[:accounts].first[:name].should == "Assets:Bank:Checking"
|
115
|
+
@entries.first[:accounts].first[:amount].should == 1000
|
116
|
+
@entries.first[:accounts].last[:name].should == "Equity:Opening Balances"
|
117
|
+
@entries.first[:accounts].last[:amount].should == -1000
|
118
|
+
|
119
|
+
@entries.last[:desc].should == "Credit card company"
|
120
|
+
@entries.last[:date].should == Date.parse("2004/05/27")
|
121
|
+
@entries.last[:accounts].first[:name].should == "Liabilities:MasterCard"
|
122
|
+
@entries.last[:accounts].first[:amount].should == 20.24
|
123
|
+
@entries.last[:accounts].last[:name].should == "Assets:Bank:Checking"
|
124
|
+
@entries.last[:accounts].last[:amount].should == -20.24
|
123
125
|
end
|
124
126
|
end
|
125
127
|
|
data/spec/reckon/options_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe '#parse_opts' do
|
4
4
|
it 'should assign to :string option' do
|
5
|
-
options = Reckon::Options.
|
5
|
+
options = Reckon::Options.parse_command_line_options(
|
6
6
|
%w[-f - --unattended --account bank],
|
7
7
|
StringIO.new('foo,bar,baz')
|
8
8
|
)
|
@@ -10,7 +10,7 @@ describe '#parse_opts' do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should require --unattended flag' do
|
13
|
-
expect { Reckon::Options.
|
13
|
+
expect { Reckon::Options.parse_command_line_options(%w[-f - --account bank]) }.to(
|
14
14
|
raise_error(RuntimeError, "--unattended is required to use STDIN as CSV source.")
|
15
15
|
)
|
16
16
|
end
|
data/spec/spec_helper.rb
CHANGED
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.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Cantino
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-
|
13
|
+
date: 2023-03-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- ".document"
|
124
124
|
- ".github/workflows/ruby.yml"
|
125
125
|
- ".gitignore"
|
126
|
+
- ".rubocop.yml"
|
126
127
|
- ".ruby-gemset"
|
127
128
|
- ".ruby-version"
|
128
129
|
- CHANGELOG.md
|
@@ -135,6 +136,7 @@ files:
|
|
135
136
|
- bin/reckon
|
136
137
|
- lib/reckon.rb
|
137
138
|
- lib/reckon/app.rb
|
139
|
+
- lib/reckon/beancount_parser.rb
|
138
140
|
- lib/reckon/cosine_similarity.rb
|
139
141
|
- lib/reckon/csv_parser.rb
|
140
142
|
- lib/reckon/date_column.rb
|
@@ -165,6 +167,7 @@ files:
|
|
165
167
|
- spec/data_fixtures/intuit_mint_example.csv
|
166
168
|
- spec/data_fixtures/invalid_header_example.csv
|
167
169
|
- spec/data_fixtures/inversed_credit_card.csv
|
170
|
+
- spec/data_fixtures/multi-line-field.csv
|
168
171
|
- spec/data_fixtures/nationwide.csv
|
169
172
|
- spec/data_fixtures/simple.csv
|
170
173
|
- spec/data_fixtures/some_other.csv
|
@@ -258,6 +261,9 @@ files:
|
|
258
261
|
- spec/integration/suntrust/input.csv
|
259
262
|
- spec/integration/suntrust/output.ledger
|
260
263
|
- spec/integration/suntrust/test_args
|
264
|
+
- spec/integration/tab_delimited_file/input.csv
|
265
|
+
- spec/integration/tab_delimited_file/output.ledger
|
266
|
+
- spec/integration/tab_delimited_file/test_args
|
261
267
|
- spec/integration/test.sh
|
262
268
|
- spec/integration/test_money_column/input.csv
|
263
269
|
- spec/integration/test_money_column/output.ledger
|