reckon 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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(EXAMPLE_LEDGER, date_format: '%Y/%m/%d')
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(s, date_format: '%Y/%m/%d').to_csv.join("\n")
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
- l = Reckon::LedgerParser.new(ledger)
87
- expect(l.entries.length).to eq(1)
88
- expect(l.entries.first[:desc]).to eq('Dinner should show up')
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
- 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)
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
- @ledger.entries.length.should == 7
108
+ @entries.length.should == 7
107
109
  end
108
110
 
109
111
  it "should parse entries correctly" do
110
- @ledger.entries.first[:desc].should == "Checking balance"
111
- @ledger.entries.first[:date].should == Date.parse("2004-05-01")
112
- @ledger.entries.first[:accounts].first[:name].should == "Assets:Bank:Checking"
113
- @ledger.entries.first[:accounts].first[:amount].should == 1000
114
- @ledger.entries.first[:accounts].last[:name].should == "Equity:Opening Balances"
115
- @ledger.entries.first[:accounts].last[:amount].should == -1000
116
-
117
- @ledger.entries.last[:desc].should == "Credit card company"
118
- @ledger.entries.last[:date].should == Date.parse("2004/05/27")
119
- @ledger.entries.last[:accounts].first[:name].should == "Liabilities:MasterCard"
120
- @ledger.entries.last[:accounts].first[:amount].should == 20.24
121
- @ledger.entries.last[:accounts].last[:name].should == "Assets:Bank:Checking"
122
- @ledger.entries.last[:accounts].last[:amount].should == -20.24
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
 
@@ -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.parse(
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.parse(%w[-f - --account bank]) }.to(
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'rspec'
3
5
  require 'reckon'
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.0
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-02-23 00:00:00.000000000 Z
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