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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebc742c8d24a74d3b38904096e66548289bde353
4
- data.tar.gz: 2f16e836465583bcb9b4e3b3a248ec7f6e591f7e
3
+ metadata.gz: 745a9c41a2a718421bbeff54a6cab8db47767c95
4
+ data.tar.gz: 839a9e0a2e2c02844001bdac55e11f8aac5642ae
5
5
  SHA512:
6
- metadata.gz: 3540762354c19f63abba8c77ce309186c7c7f7f03549fac25517ea3a0057f52e08534820edf3cf4007e7d999bd7d4af2a4ce172c0ecd86c0458c89120c8bc07a
7
- data.tar.gz: df3519d1e91dacfddfd85677d58634daf5289791e32013aef7a7732e6fb9d514d5bd5b29f80d0df1c3a314ba98d9408d2fb6f05a3a2028ba66d785ba27a06e8e
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
- parser = BankStatementParser::HSBC.new
26
+ #bank_symbol = :hsbc
27
+ bank_symbol = :santander
27
28
 
28
29
  # Attempt to parse the specified file
29
- parser.parse ARGV[0]
30
+ bank_statement = BankStatementParser.parse ARGV[0], bank_symbol
30
31
 
31
- puts YAML.dump(parser.bank_statement)
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
- open(path).read
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 name) bank
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, bank = 'HSBC'
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bank_statement_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Dawson