bank_statement_parser 0.1.11 → 1.0.0
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 +4 -4
- data/bin/bank_statement_to_yaml.rb +4 -3
- data/lib/bank_statement_parser/base.rb +8 -1
- data/lib/bank_statement_parser.rb +10 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 745a9c41a2a718421bbeff54a6cab8db47767c95
|
4
|
+
data.tar.gz: 839a9e0a2e2c02844001bdac55e11f8aac5642ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15bcbe26137f90c85536d0b87b18b18712e579bdd7f88b8dc8c4b24f258eaac30457b96014adf3b929a9f8eee4ab2c345adc5fa4aff5a9c47b23e496ad112d62
|
7
|
+
data.tar.gz: 4e60bf99feb68775bb5098eb0b872c8d3c7b3ae585975627e2fdc7eb46a651244ccbc20d549e7099e604d266c89dabf5fa0172a0048a51afdbdf500b21cd65a6
|
@@ -23,9 +23,10 @@ require 'yaml'
|
|
23
23
|
|
24
24
|
require 'bank_statement_parser'
|
25
25
|
|
26
|
-
|
26
|
+
#bank_symbol = :hsbc
|
27
|
+
bank_symbol = :santander
|
27
28
|
|
28
29
|
# Attempt to parse the specified file
|
29
|
-
|
30
|
+
bank_statement = BankStatementParser.parse ARGV[0], bank_symbol
|
30
31
|
|
31
|
-
puts YAML.dump(
|
32
|
+
puts YAML.dump(bank_statement)
|
@@ -50,7 +50,11 @@ module BankStatementParser
|
|
50
50
|
when String
|
51
51
|
# Is the path a URI?
|
52
52
|
if path =~ URI::regexp(%w(ftp http https))
|
53
|
-
|
53
|
+
begin
|
54
|
+
open(path).read
|
55
|
+
rescue OpenURI::HTTPError => e
|
56
|
+
raise "Failed to read URI #{path}: #{e}"
|
57
|
+
end
|
54
58
|
else
|
55
59
|
raise "Expected a text file path" unless
|
56
60
|
path =~ /\.txt\z/
|
@@ -75,6 +79,9 @@ module BankStatementParser
|
|
75
79
|
raise "Failed to find sort code" if sort_code.nil?
|
76
80
|
raise "Failed to find account number" if account_number.nil?
|
77
81
|
raise "Failed to find statement date" if statement_date.nil?
|
82
|
+
raise "Failed to find account name" if name.nil?
|
83
|
+
raise "Failed to find opening balance" if opening_balance.nil?
|
84
|
+
raise "Failed to find closing balance" if closing_balance.nil?
|
78
85
|
end
|
79
86
|
|
80
87
|
protected
|
@@ -17,6 +17,7 @@
|
|
17
17
|
|
18
18
|
require 'logger'
|
19
19
|
require 'bank_statement_parser/hsbc'
|
20
|
+
require 'bank_statement_parser/santander'
|
20
21
|
module BankStatementParser
|
21
22
|
|
22
23
|
@@logger = Logger.new(STDERR)
|
@@ -27,10 +28,17 @@ module BankStatementParser
|
|
27
28
|
@@logger = logger
|
28
29
|
end
|
29
30
|
|
30
|
-
# Parse the specified statement file, for the specified (by
|
31
|
+
# Parse the specified statement file, for the specified (by symbol) bank
|
31
32
|
#
|
32
33
|
# Returns an instance of BankStatement
|
33
|
-
def self.parse path,
|
34
|
+
def self.parse path, bank_symbol = :hsbc
|
35
|
+
# Known banks should all be tabulated here
|
36
|
+
banks = {
|
37
|
+
hsbc: 'HSBC',
|
38
|
+
santander: 'Santander',
|
39
|
+
}
|
40
|
+
bank = banks[bank_symbol] or raise "Unknown bank #{bank_symbol}"
|
41
|
+
|
34
42
|
parser_class = Kernel.const_get(self.name + '::' + bank)
|
35
43
|
raise "No parser for #{bank} statements" unless Class == parser_class.class
|
36
44
|
|