bank_statement_parser 0.0.8 → 0.0.9

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: 2e0cc6b14c90e91e82a2990148f616ead57a643d
4
- data.tar.gz: 4deac2be2ea2f4dbca9cbbeb9fc82d590401a54d
3
+ metadata.gz: 99db3d2a3fcc834b9f3884962c7f4eaa3032f67e
4
+ data.tar.gz: 7f410faff7bb5d2918d533542230ed79b3d1fe3e
5
5
  SHA512:
6
- metadata.gz: 5abeee3da3cd87df2109ad8cd58a7421eeff977c0c0fd89514c8d9f9c0e37f88420aa579ca5eeb068dfe63bb60b370483a395fa237d3709dfd1b0af742314a69
7
- data.tar.gz: 6230eeccdca54d1da494eee62e4595888d95ed2d2a7245c1eec95688fc547f32a43c46fe98b32fe7f179053f1bf8e563a643facf2de72da13401c0e0389034b0
6
+ metadata.gz: f474d0ec9337ebcf58d78b2014ffd3d005c6e2615380d24a0d0a3bc994695dcd0e1b9e632279ec673753a187a7d0ddcaae1c5763d2089e46d7e47aedc34effa7
7
+ data.tar.gz: 741575356ffbc36d4babcd08becf83b66e2dcadfa320c3e913a064c04e0ff0a829165ed831ed153318da7aa8941cb2d1f8347bc44918e2f6b625a33a313348af
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Parse the specified HSBC bank statement file to YAML
4
+
5
+ # Copyright 2015 Simon Dawson <spdawson@gmail.com>
6
+
7
+ # This file is part of bank_statement_parser.
8
+ #
9
+ # bank_statement_parser is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # bank_statement_parser is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with bank_statement_parser. If not, see <http://www.gnu.org/licenses/>.
21
+
22
+ require 'bank_statement_parser'
23
+
24
+ parser = BankStatementParser::HSBC.new
25
+
26
+ # Attempt to parse the specified file
27
+ parser.parse ARGV[0]
28
+
29
+ # Statement metadata
30
+ puts <<METADATA
31
+ bank_statement:
32
+ account_number: #{parser.account_number}
33
+ sort_code: #{parser.sort_code}
34
+ statement_date: #{parser.statement_date}
35
+ METADATA
36
+
37
+ # Statement records
38
+ parser.records.each do |record|
39
+ puts <<RECORD
40
+ records:
41
+ date: #{record.date}
42
+ type: #{record.type}
43
+ credit: #{record.credit}
44
+ amount: #{record.amount || ''}
45
+ detail: #{record.detail}
46
+ balance: #{record.balance || ''}
47
+ RECORD
48
+ end
@@ -65,7 +65,7 @@ module BankStatementParser
65
65
 
66
66
  # Parse statement date
67
67
  date_string = Regexp.last_match(:statement_date)
68
- @statement_date = DateTime.parse(date_string)
68
+ @statement_date = Date.parse(date_string)
69
69
  elsif line =~ /\A(?<date_range_start>\d+\s+(?:#{MONTHS.join('|')})(?:\s+\d{4})?)\s+to\s+(?<date_range_end>\d+\s+(?:#{MONTHS.join('|')})\s+\d{4})\b/
70
70
  logger.debug { "Found statement date (2nd form)" }
71
71
  @statement_format = StatementFormat::FORMAT_2ND
@@ -75,7 +75,7 @@ module BankStatementParser
75
75
  logger.debug { "Found statement date range #{date_range_start}-#{date_range_end}" }
76
76
 
77
77
  # Parse range end date
78
- @statement_date = DateTime.parse(date_range_end)
78
+ @statement_date = Date.parse(date_range_end)
79
79
  end
80
80
  end
81
81
 
@@ -162,7 +162,9 @@ module BankStatementParser
162
162
  #
163
163
  # We need to figure out the correct year, from the statement date.
164
164
  raise "No statement date" unless @statement_date
165
- record_date = record_date.change(year: @statement_date.year)
165
+ record_date = Date.new(@statement_date.year,
166
+ record_date.month,
167
+ record_date.day)
166
168
  logger.debug { "record date #{record_date}" }
167
169
  if @statement_date.month != record_date.month
168
170
  logger.debug { "record month differs from statement month" }
@@ -307,7 +309,7 @@ module BankStatementParser
307
309
  date_string = col_fragments[0]
308
310
  unless date_string.nil?
309
311
  begin
310
- @cached_statement_date = DateTime.parse(date_string)
312
+ @cached_statement_date = Date.parse(date_string)
311
313
  @cached_statement_date =
312
314
  fix_record_date_year(@cached_statement_date)
313
315
  rescue ArgumentError => e
@@ -38,9 +38,9 @@ module BankStatementParser
38
38
  "%s:%s:%s:%s:%s:%s" % [date,
39
39
  type,
40
40
  credit.to_s,
41
- (amount.nil? ? '' : amount.to_s),
41
+ (amount || ''),
42
42
  detail,
43
- (balance.nil? ? '' : balance.to_s)]
43
+ (balance || '')]
44
44
  end
45
45
 
46
46
  # Equality test
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.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Dawson
@@ -12,16 +12,18 @@ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A gem for parsing bank statements
14
14
  email: spdawson@gmail.com
15
- executables: []
15
+ executables:
16
+ - bank_statement_to_yaml.rb
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
20
+ - bin/bank_statement_to_yaml.rb
19
21
  - lib/bank_statement_parser.rb
20
22
  - lib/bank_statement_parser/base.rb
21
23
  - lib/bank_statement_parser/hsbc.rb
22
24
  - lib/bank_statement_parser/statement_record.rb
23
25
  - lib/bank_statement_parser/utils.rb
24
- homepage: http://rubygems.org/gems/bank_statement_parser
26
+ homepage: https://github.com/spdawson/bank_statement_parser
25
27
  licenses:
26
28
  - GPLv3
27
29
  metadata: {}