dillinger 0.0.1.pre
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 +7 -0
- data/lib/dillinger.rb +40 -0
- data/lib/dillinger/parser/asb_csv.rb +49 -0
- data/lib/dillinger/parser/asb_tdv.rb +49 -0
- data/lib/dillinger/parser/base.rb +40 -0
- data/lib/dillinger/parser/ofx.rb +46 -0
- data/lib/dillinger/parser/qif.rb +47 -0
- data/lib/dillinger/parser/westpac_csv.rb +38 -0
- data/lib/dillinger/transaction.rb +34 -0
- data/lib/dillinger/version.rb +3 -0
- data/spec/dillinger_spec.rb +55 -0
- data/spec/parser/asb_csv_spec.rb +50 -0
- data/spec/parser/asb_tdv_spec.rb +50 -0
- data/spec/parser/ofx_spec.rb +50 -0
- data/spec/parser/qif_spec.rb +50 -0
- data/spec/parser/westpac_csv_spec.rb +50 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/support/fixtures_helper.rb +5 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 40e620ba11b9b2420cbdf39a4ab3b6d15f6281fc
|
4
|
+
data.tar.gz: 3d918292e621f1a53a12df4b936d886071defc63
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dfc25c2f6e0a6e5df84997ccdd84f0fc032639a4ebdb9a4af60fa9e1d0369a08f0ab580426863d60150ba950c93d46bbc4d3130f1a118e559c901fbfa2f239b4
|
7
|
+
data.tar.gz: d75dd753df897eceb6b7d39809f6cb21f142d97db1745b17c9d93126a9942ecb6d9766c6195638b6dec0a8fbf8b5b151a35108537df64d9b90ef023730b406fc
|
data/lib/dillinger.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
|
3
|
+
require 'dillinger/version'
|
4
|
+
require 'dillinger/transaction'
|
5
|
+
require 'dillinger/parser/base'
|
6
|
+
require 'dillinger/parser/ofx'
|
7
|
+
require 'dillinger/parser/qif'
|
8
|
+
require 'dillinger/parser/westpac_csv'
|
9
|
+
require 'dillinger/parser/asb_tdv'
|
10
|
+
require 'dillinger/parser/asb_csv'
|
11
|
+
|
12
|
+
# = Dillinger
|
13
|
+
#
|
14
|
+
# Dillinger is a library for detecting and parsing bank statement formats in Ruby.
|
15
|
+
module Dillinger
|
16
|
+
##
|
17
|
+
# Detects the statement format and returns an initialized parser.
|
18
|
+
# If it can't detect the file format it returns false.
|
19
|
+
#
|
20
|
+
# ==== Example:
|
21
|
+
# # OFX file
|
22
|
+
# Dillinger.new(open("./path/to/statement.ofx"))
|
23
|
+
# # => #<Dillinger::Parser::Ofx ...>
|
24
|
+
#
|
25
|
+
# # QIF file
|
26
|
+
# Dillinger.new(open("./path/to/statement.qif"))
|
27
|
+
# # => #<Dillinger::Parser::Qif ...>
|
28
|
+
#
|
29
|
+
# # Unknown file
|
30
|
+
# Dillinger.new(open("./path/to/statement.php"))
|
31
|
+
# # => false
|
32
|
+
def self.new(file)
|
33
|
+
Parser.constants.each do |const|
|
34
|
+
klass = Parser.const_get(const)
|
35
|
+
return klass.new(file) if klass.test(file.dup)
|
36
|
+
end
|
37
|
+
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Dillinger
|
4
|
+
module Parser
|
5
|
+
class AsbCsv < Base
|
6
|
+
HEADER_LINE = /Date,Unique Id,Tran Type,Cheque Number,Payee,Memo,Amount/
|
7
|
+
|
8
|
+
TYPES = {
|
9
|
+
'TFR OUT' => 'TRANSFER',
|
10
|
+
'EFTPOS' => 'EFTPOS',
|
11
|
+
'D/D' => 'DIRECTDEBIT',
|
12
|
+
'D/C' => 'DIRECTCREDIT',
|
13
|
+
'LOAN INT' => 'DEBIT',
|
14
|
+
'LOAN PRIN' => 'DEBIT',
|
15
|
+
'XFER' => 'TRANSFER',
|
16
|
+
'POS' => 'EFTPOS',
|
17
|
+
'DEPOSIT' => 'DEPOSIT',
|
18
|
+
'DIRECTDEP' => 'DEPOSIT'
|
19
|
+
}
|
20
|
+
|
21
|
+
def self.test(file)
|
22
|
+
file.rewind
|
23
|
+
!HEADER_LINE.match(file.take(7).last).nil?
|
24
|
+
rescue
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse
|
29
|
+
file.rewind
|
30
|
+
data = file.read.split("\n")
|
31
|
+
data.delete("\r")
|
32
|
+
6.times { data.delete_at(0) }
|
33
|
+
CSV.parse(data.join("\n").strip, headers: true, converters: :numeric, header_converters: :symbol) do |row|
|
34
|
+
transaction = Dillinger::Transaction.new
|
35
|
+
transaction.amount = row.field(:amount).to_f
|
36
|
+
transaction.date = Date.strptime(row.field(:date), '%Y/%m/%d')
|
37
|
+
transaction.description = ''
|
38
|
+
transaction.particulars = row.field(:memo)
|
39
|
+
transaction.payee = row.field(:payee)
|
40
|
+
transaction.reference = ''
|
41
|
+
transaction.type = TYPES[row.field(:tran_type)] || row.field(:tran_type)
|
42
|
+
transaction.unique_id = transaction.generate_unique_id
|
43
|
+
|
44
|
+
add_transaction transaction
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Dillinger
|
4
|
+
module Parser
|
5
|
+
class AsbTdv < Base
|
6
|
+
HEADER_LINE = /Date\tUnique Id\tTran Type\tCheque Number\tPayee\tMemo\tAmount/
|
7
|
+
|
8
|
+
TYPES = {
|
9
|
+
'TFR OUT' => 'TRANSFER',
|
10
|
+
'EFTPOS' => 'EFTPOS',
|
11
|
+
'D/D' => 'DIRECTDEBIT',
|
12
|
+
'D/C' => 'DIRECTCREDIT',
|
13
|
+
'LOAN INT' => 'DEBIT',
|
14
|
+
'LOAN PRIN' => 'DEBIT',
|
15
|
+
'XFER' => 'TRANSFER',
|
16
|
+
'POS' => 'EFTPOS',
|
17
|
+
'DEPOSIT' => 'DEPOSIT',
|
18
|
+
'DIRECTDEP' => 'DEPOSIT'
|
19
|
+
}
|
20
|
+
|
21
|
+
def self.test(file)
|
22
|
+
file.rewind
|
23
|
+
!HEADER_LINE.match(file.take(7).last).nil?
|
24
|
+
rescue
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse
|
29
|
+
file.rewind
|
30
|
+
data = file.read.split("\n")
|
31
|
+
data.delete("\r")
|
32
|
+
6.times { data.delete_at(0) }
|
33
|
+
CSV.parse(data.join("\n").strip, headers: true, converters: :numeric, header_converters: :symbol, col_sep: "\t") do |row|
|
34
|
+
transaction = Dillinger::Transaction.new
|
35
|
+
transaction.amount = row.field(:amount).to_f
|
36
|
+
transaction.date = Date.strptime(row.field(:date), '%Y/%m/%d')
|
37
|
+
transaction.description = ''
|
38
|
+
transaction.particulars = row.field(:memo)
|
39
|
+
transaction.payee = row.field(:payee)
|
40
|
+
transaction.reference = ''
|
41
|
+
transaction.type = TYPES[row.field(:tran_type)] || row.field(:tran_type)
|
42
|
+
transaction.unique_id = transaction.generate_unique_id
|
43
|
+
|
44
|
+
add_transaction transaction
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'digest'
|
3
|
+
|
4
|
+
module Dillinger
|
5
|
+
module Parser
|
6
|
+
# = Dillinger::Parser::Base
|
7
|
+
#
|
8
|
+
# Dillinger::Parser::Base is the generic parser that others can inherit from.
|
9
|
+
class Base
|
10
|
+
attr_accessor :file, :transactions
|
11
|
+
|
12
|
+
##
|
13
|
+
# self.test must be implmented by parser that inherit from Dillinger::Parser::Base.
|
14
|
+
def self.test(_file)
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# parse must be implmented by parser that inherit from Dillinger::Parser::Base.
|
20
|
+
def parse
|
21
|
+
fail StandardError.new('parse has not been implemented.')
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# All parsers are initilized with a file.
|
26
|
+
def initialize(file)
|
27
|
+
@file = file
|
28
|
+
@transactions = Set.new
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
##
|
34
|
+
# Appends a transaction to the transaction set.
|
35
|
+
def add_transaction(transaction)
|
36
|
+
transactions << transaction
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'ofx'
|
2
|
+
|
3
|
+
module Dillinger
|
4
|
+
module Parser
|
5
|
+
class Ofx < Base
|
6
|
+
TYPES = {
|
7
|
+
xfer: 'TRANSFER',
|
8
|
+
pos: 'EFTPOS',
|
9
|
+
directdebit: 'DIRECTDEBIT',
|
10
|
+
directdep: 'DEPOSIT',
|
11
|
+
debit: 'DEBIT'
|
12
|
+
}
|
13
|
+
|
14
|
+
def self.test(file)
|
15
|
+
file.rewind
|
16
|
+
OFX::Parser::Base.new(file)
|
17
|
+
true
|
18
|
+
rescue
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse
|
23
|
+
ofx_parser.account.transactions.each do |t|
|
24
|
+
transaction = Dillinger::Transaction.new
|
25
|
+
transaction.amount = t.amount.to_f
|
26
|
+
transaction.date = t.posted_at.to_date
|
27
|
+
transaction.description = t.payee
|
28
|
+
transaction.particulars = t.memo
|
29
|
+
transaction.payee = t.name
|
30
|
+
transaction.reference = t.ref_number
|
31
|
+
transaction.type = TYPES[t.type] || t.type
|
32
|
+
transaction.unique_id = t.fit_id
|
33
|
+
|
34
|
+
add_transaction transaction
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def ofx_parser
|
41
|
+
file.rewind
|
42
|
+
@ofx_parser ||= OFX::Parser::Base.new(file).parser
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'qif'
|
2
|
+
|
3
|
+
module Dillinger
|
4
|
+
module Parser
|
5
|
+
class Qif < Base
|
6
|
+
TYPES = {
|
7
|
+
'TFROUT' => 'TRANSFER',
|
8
|
+
'EFTPOS' => 'EFTPOS',
|
9
|
+
'DIRDEB' => 'DIRECTDEBIT',
|
10
|
+
'DIRCRE' => 'DIRECTCREDIT',
|
11
|
+
'LOANRE' => 'DEBIT',
|
12
|
+
'DEPOSIT' => 'DEPOSIT'
|
13
|
+
}
|
14
|
+
|
15
|
+
def self.test(file)
|
16
|
+
file.rewind
|
17
|
+
::Qif::Reader.new(file)
|
18
|
+
true
|
19
|
+
rescue
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse
|
24
|
+
qif_parser.transactions.each do |t|
|
25
|
+
transaction = Dillinger::Transaction.new
|
26
|
+
transaction.amount = t.amount.to_f
|
27
|
+
transaction.date = t.date
|
28
|
+
transaction.description = ''
|
29
|
+
transaction.particulars = t.memo
|
30
|
+
transaction.payee = t.payee.to_s
|
31
|
+
transaction.reference = ''
|
32
|
+
transaction.type = TYPES[t.number] || t.number
|
33
|
+
transaction.unique_id = transaction.generate_unique_id
|
34
|
+
|
35
|
+
add_transaction transaction
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def qif_parser
|
42
|
+
file.rewind
|
43
|
+
@qif_parser ||= ::Qif::Reader.new(file)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Dillinger
|
4
|
+
module Parser
|
5
|
+
class WestpacCsv < Base
|
6
|
+
TYPES = {
|
7
|
+
'EFTPOS TRANSACTION' => 'EFTPOS',
|
8
|
+
'ONLINE BANKING' => 'TRANSFER',
|
9
|
+
'BILL PAYMENT' => 'DEBIT'
|
10
|
+
}
|
11
|
+
|
12
|
+
HEADER_LINE = /Date,Amount,Other Party,Description,Reference,Particulars,Analysis Code/
|
13
|
+
|
14
|
+
def self.test(file)
|
15
|
+
file.rewind
|
16
|
+
!HEADER_LINE.match(file.readline).nil?
|
17
|
+
rescue
|
18
|
+
false
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse
|
22
|
+
file.rewind
|
23
|
+
CSV.parse(file.read, headers: true, converters: :numeric, header_converters: :symbol) do |row|
|
24
|
+
transaction = Dillinger::Transaction.new
|
25
|
+
transaction.amount = row.field(:amount).to_f
|
26
|
+
transaction.date = Date.parse(row.field(:date))
|
27
|
+
transaction.description = row.field(:analysis_code)
|
28
|
+
transaction.payee = row.field(:other_party)
|
29
|
+
transaction.reference = row.field(:reference)
|
30
|
+
transaction.type = TYPES[row.field(:description)] || row.field(:description)
|
31
|
+
transaction.unique_id = transaction.generate_unique_id
|
32
|
+
|
33
|
+
add_transaction transaction
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Dillinger
|
2
|
+
# = Dillinger::Transaction
|
3
|
+
#
|
4
|
+
# Dillinger::Transaction represents a generic bank transaction.
|
5
|
+
class Transaction
|
6
|
+
include ActiveModel::Model
|
7
|
+
include ActiveModel::Serialization
|
8
|
+
|
9
|
+
FIELDS = [:date, :amount, :payee, :description, :reference, :particulars, :type, :unique_id]
|
10
|
+
|
11
|
+
attr_accessor *FIELDS
|
12
|
+
|
13
|
+
def attributes
|
14
|
+
Hash[FIELDS.map { |k| [k, send(k)] }]
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# Generates and returns a unique identifier for the transaction.
|
19
|
+
def generate_unique_id
|
20
|
+
Digest::SHA256.hexdigest unique_id_elements.join
|
21
|
+
end
|
22
|
+
|
23
|
+
def unique_id_elements
|
24
|
+
[
|
25
|
+
date,
|
26
|
+
amount.to_f,
|
27
|
+
description,
|
28
|
+
particulars,
|
29
|
+
payee,
|
30
|
+
reference
|
31
|
+
].map(&:to_s).map(&:downcase)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dillinger do
|
4
|
+
it 'has a version number' do
|
5
|
+
expect(Dillinger::VERSION).not_to be nil
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'invalid file' do
|
9
|
+
subject { described_class.new(fixture('blank.txt')) }
|
10
|
+
|
11
|
+
it 'is false' do
|
12
|
+
expect(subject).to be false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'QIF' do
|
17
|
+
subject { described_class.new(fixture('example_qif.qif')) }
|
18
|
+
|
19
|
+
it 'selects the corect parser for QIF format' do
|
20
|
+
expect(subject).to be_instance_of(Dillinger::Parser::Qif)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'OFX' do
|
25
|
+
subject { described_class.new(fixture('example_ofx.ofx')) }
|
26
|
+
|
27
|
+
it 'selects the corect parser for OFX format' do
|
28
|
+
expect(subject).to be_instance_of(Dillinger::Parser::Ofx)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'Westpac CSV' do
|
33
|
+
subject { described_class.new(fixture('example_westpac_csv.csv')) }
|
34
|
+
|
35
|
+
it 'selects the corect parser for Westpac CSV format' do
|
36
|
+
expect(subject).to be_instance_of(Dillinger::Parser::WestpacCsv)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'ASB CSV' do
|
41
|
+
subject { described_class.new(fixture('example_asb_csv.csv')) }
|
42
|
+
|
43
|
+
it 'selects the corect parser for ASB CSV format' do
|
44
|
+
expect(subject).to be_instance_of(Dillinger::Parser::AsbCsv)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'ASB TDV' do
|
49
|
+
subject { described_class.new(fixture('example_asb_tdv.tdv')) }
|
50
|
+
|
51
|
+
it 'selects the corect parser for ASB TDV format' do
|
52
|
+
expect(subject).to be_instance_of(Dillinger::Parser::AsbTdv)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dillinger::Parser::AsbCsv do
|
4
|
+
let(:statement_file) { fixture('example_asb_csv.csv') }
|
5
|
+
let(:other_file) { fixture('example_ofx.ofx') }
|
6
|
+
|
7
|
+
subject { described_class.new(statement_file) }
|
8
|
+
|
9
|
+
describe '.test' do
|
10
|
+
specify do
|
11
|
+
expect(described_class.test(statement_file)).to be true
|
12
|
+
end
|
13
|
+
|
14
|
+
specify do
|
15
|
+
expect(described_class.test(other_file)).to be false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#parse' do
|
20
|
+
before do
|
21
|
+
subject.parse
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has the correct transaction amounts' do
|
25
|
+
expect(subject.transactions.map(&:amount)).to eq [
|
26
|
+
-500.0,
|
27
|
+
-3.8,
|
28
|
+
-456.78,
|
29
|
+
5678.9
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has the correct transaction types' do
|
34
|
+
expect(subject.transactions.map(&:type)).to eq %w(TRANSFER EFTPOS DEBIT DEPOSIT)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'has the correct transaction dates' do
|
38
|
+
expect(subject.transactions.map(&:date)).to eq [
|
39
|
+
Date.new(2014, 12, 20),
|
40
|
+
Date.new(2014, 12, 21),
|
41
|
+
Date.new(2014, 12, 22),
|
42
|
+
Date.new(2014, 12, 23)
|
43
|
+
]
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'has the correct transaction unique ids' do
|
47
|
+
expect(subject.transactions.map(&:unique_id)).to eq %w(4f572a400796a3304b67b13f9fd8eabb00e70c5bc50c212c44b6716b0b4abb5a b5264781928fd04c6ada530a97755ad58ba2aeb2f26e65ec7960cd240d9b2a05 ba3594e8b4042c94268ab26ce12c13086d08e62c7f7e24730abfc29d2fd754fd b6fe974ae17fa9fc799b31cd6251ecbb3ab9f7a498a7bc72acc4503e24229b3e)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dillinger::Parser::AsbTdv do
|
4
|
+
let(:statement_file) { fixture('example_asb_tdv.tdv') }
|
5
|
+
let(:other_file) { fixture('example_ofx.ofx') }
|
6
|
+
|
7
|
+
subject { described_class.new(statement_file) }
|
8
|
+
|
9
|
+
describe '.test' do
|
10
|
+
specify do
|
11
|
+
expect(described_class.test(statement_file)).to be true
|
12
|
+
end
|
13
|
+
|
14
|
+
specify do
|
15
|
+
expect(described_class.test(other_file)).to be false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#parse' do
|
20
|
+
before do
|
21
|
+
subject.parse
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has the correct transaction amounts' do
|
25
|
+
expect(subject.transactions.map(&:amount)).to eq [
|
26
|
+
-500.0,
|
27
|
+
-3.8,
|
28
|
+
-456.78,
|
29
|
+
5678.9
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has the correct transaction types' do
|
34
|
+
expect(subject.transactions.map(&:type)).to eq %w(TRANSFER EFTPOS DEBIT DEPOSIT)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'has the correct transaction dates' do
|
38
|
+
expect(subject.transactions.map(&:date)).to eq [
|
39
|
+
Date.new(2014, 12, 20),
|
40
|
+
Date.new(2014, 12, 21),
|
41
|
+
Date.new(2014, 12, 22),
|
42
|
+
Date.new(2014, 12, 23)
|
43
|
+
]
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'has the correct transaction unique ids' do
|
47
|
+
expect(subject.transactions.map(&:unique_id)).to eq %w(4f572a400796a3304b67b13f9fd8eabb00e70c5bc50c212c44b6716b0b4abb5a b5264781928fd04c6ada530a97755ad58ba2aeb2f26e65ec7960cd240d9b2a05 ba3594e8b4042c94268ab26ce12c13086d08e62c7f7e24730abfc29d2fd754fd b6fe974ae17fa9fc799b31cd6251ecbb3ab9f7a498a7bc72acc4503e24229b3e)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dillinger::Parser::Ofx do
|
4
|
+
let(:statement_file) { fixture('example_ofx.ofx') }
|
5
|
+
let(:other_file) { fixture('example_qif.qif') }
|
6
|
+
|
7
|
+
subject { described_class.new(statement_file) }
|
8
|
+
|
9
|
+
describe '.test' do
|
10
|
+
specify do
|
11
|
+
expect(described_class.test(statement_file)).to be true
|
12
|
+
end
|
13
|
+
|
14
|
+
specify do
|
15
|
+
expect(described_class.test(other_file)).to be false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#parse' do
|
20
|
+
before do
|
21
|
+
subject.parse
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has the correct transaction amounts' do
|
25
|
+
expect(subject.transactions.map(&:amount)).to eq [
|
26
|
+
-500.0,
|
27
|
+
-3.8,
|
28
|
+
-456.78,
|
29
|
+
5678.9
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has the correct transaction types' do
|
34
|
+
expect(subject.transactions.map(&:type)).to eq %w(TRANSFER EFTPOS DEBIT DEPOSIT)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'has the correct transaction dates' do
|
38
|
+
expect(subject.transactions.map(&:date)).to eq [
|
39
|
+
Date.new(2014, 12, 20),
|
40
|
+
Date.new(2014, 12, 21),
|
41
|
+
Date.new(2014, 12, 22),
|
42
|
+
Date.new(2014, 12, 23)
|
43
|
+
]
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'has the correct transaction unique ids' do
|
47
|
+
expect(subject.transactions.map(&:unique_id)).to eq %w(2014122001 2014122101 2014122201 2014122301)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dillinger::Parser::Qif do
|
4
|
+
let(:statement_file) { fixture('example_qif.qif') }
|
5
|
+
let(:other_file) { fixture('example_ofx.ofx') }
|
6
|
+
|
7
|
+
subject { described_class.new(statement_file) }
|
8
|
+
|
9
|
+
describe '.test' do
|
10
|
+
specify do
|
11
|
+
expect(described_class.test(statement_file)).to be true
|
12
|
+
end
|
13
|
+
|
14
|
+
specify do
|
15
|
+
expect(described_class.test(other_file)).to be false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#parse' do
|
20
|
+
before do
|
21
|
+
subject.parse
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has the correct transaction amounts' do
|
25
|
+
expect(subject.transactions.map(&:amount)).to eq [
|
26
|
+
-500.0,
|
27
|
+
-3.8,
|
28
|
+
-456.78,
|
29
|
+
5678.9
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has the correct transaction types' do
|
34
|
+
expect(subject.transactions.map(&:type)).to eq %w(TRANSFER EFTPOS DEBIT DEPOSIT)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'has the correct transaction dates' do
|
38
|
+
expect(subject.transactions.map(&:date)).to eq [
|
39
|
+
Date.new(2014, 12, 20),
|
40
|
+
Date.new(2014, 12, 21),
|
41
|
+
Date.new(2014, 12, 22),
|
42
|
+
Date.new(2014, 12, 23)
|
43
|
+
]
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'has the correct transaction unique ids' do
|
47
|
+
expect(subject.transactions.map(&:unique_id)).to eq %w(4f572a400796a3304b67b13f9fd8eabb00e70c5bc50c212c44b6716b0b4abb5a b5264781928fd04c6ada530a97755ad58ba2aeb2f26e65ec7960cd240d9b2a05 ba3594e8b4042c94268ab26ce12c13086d08e62c7f7e24730abfc29d2fd754fd b6fe974ae17fa9fc799b31cd6251ecbb3ab9f7a498a7bc72acc4503e24229b3e)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dillinger::Parser::WestpacCsv do
|
4
|
+
let(:statement_file) { fixture('example_westpac_csv.csv') }
|
5
|
+
let(:other_file) { fixture('example_ofx.ofx') }
|
6
|
+
|
7
|
+
subject { described_class.new(statement_file) }
|
8
|
+
|
9
|
+
describe '.test' do
|
10
|
+
specify do
|
11
|
+
expect(described_class.test(statement_file)).to be true
|
12
|
+
end
|
13
|
+
|
14
|
+
specify do
|
15
|
+
expect(described_class.test(other_file)).to be false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#parse' do
|
20
|
+
before do
|
21
|
+
subject.parse
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has the correct transaction amounts' do
|
25
|
+
expect(subject.transactions.map(&:amount)).to eq [
|
26
|
+
-500.0,
|
27
|
+
-3.8,
|
28
|
+
-456.78,
|
29
|
+
5678.9
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has the correct transaction types' do
|
34
|
+
expect(subject.transactions.map(&:type)).to eq %w(TRANSFER EFTPOS DEBIT DEPOSIT)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'has the correct transaction dates' do
|
38
|
+
expect(subject.transactions.map(&:date)).to eq [
|
39
|
+
Date.new(2014, 12, 20),
|
40
|
+
Date.new(2014, 12, 21),
|
41
|
+
Date.new(2014, 12, 22),
|
42
|
+
Date.new(2014, 12, 23)
|
43
|
+
]
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'has the correct transaction unique ids' do
|
47
|
+
expect(subject.transactions.map(&:unique_id)).to eq %w(1639fc32c7a91d790154c289a1074dc00381091318222cd01938825decd2cfbc aec13f2da75476a5dfa30aa06731226dda8baa366f277462d43b229f7033f54b ad0c849fc78c469770d9380e6e3a8237425eafb9067e1d85ddf37b9a284349ba 22bdba973f86363a986c7cc4918d630177cf9df00d06aeec768ab7c8e0277302)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dillinger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kale Worsley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activemodel
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ofx
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: qif
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Dillinger is a library for detecting and parsing bank statements in Ruby.
|
98
|
+
email: kale@worsley.co.nz
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- lib/dillinger.rb
|
104
|
+
- lib/dillinger/parser/asb_csv.rb
|
105
|
+
- lib/dillinger/parser/asb_tdv.rb
|
106
|
+
- lib/dillinger/parser/base.rb
|
107
|
+
- lib/dillinger/parser/ofx.rb
|
108
|
+
- lib/dillinger/parser/qif.rb
|
109
|
+
- lib/dillinger/parser/westpac_csv.rb
|
110
|
+
- lib/dillinger/transaction.rb
|
111
|
+
- lib/dillinger/version.rb
|
112
|
+
- spec/dillinger_spec.rb
|
113
|
+
- spec/parser/asb_csv_spec.rb
|
114
|
+
- spec/parser/asb_tdv_spec.rb
|
115
|
+
- spec/parser/ofx_spec.rb
|
116
|
+
- spec/parser/qif_spec.rb
|
117
|
+
- spec/parser/westpac_csv_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
- spec/support/fixtures_helper.rb
|
120
|
+
homepage: https://github.com/dotledger/dillinger
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 1.3.1
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.4.5
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Ruby Bank Statement Parsing Library
|
144
|
+
test_files:
|
145
|
+
- spec/dillinger_spec.rb
|
146
|
+
- spec/parser/asb_csv_spec.rb
|
147
|
+
- spec/parser/asb_tdv_spec.rb
|
148
|
+
- spec/parser/ofx_spec.rb
|
149
|
+
- spec/parser/qif_spec.rb
|
150
|
+
- spec/parser/westpac_csv_spec.rb
|
151
|
+
- spec/spec_helper.rb
|
152
|
+
- spec/support/fixtures_helper.rb
|
153
|
+
has_rdoc:
|