bank_statement_parser 1.0.1 → 2.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: 5e74b252e6d34c2c9c5cf38c3c83fa7311346377
4
- data.tar.gz: 6b08682abafbf2a6408174c78d7794014a61aebf
3
+ metadata.gz: 89a85ada90812b38dbb5aff866c06861ce838fb4
4
+ data.tar.gz: 6abce3b54e55d0838796fbb3da3d4f45766687b0
5
5
  SHA512:
6
- metadata.gz: b08d15003a8aef7270479d43dab7697103075467e4c0d9a9778ecb08e3a24756ef93a14f57cfb49e09097d381a6717ba520840ca266407c3564d922c45898e0e
7
- data.tar.gz: ae5c0fc92af82930c489b31b4ef811bf5875263aafbeaaa8cec7b4f5968efe2662e1f9682df49242f44f19b0a7a17e2910ae78723f5262c726b0d43ad1120428
6
+ metadata.gz: ba59fef8328bcf716b38198b89c0da1f7325f1aeaa37871d8d3b52ac90cc8d37c476a5b3bbf53105a9f447ea84d0284b802676b810fc2b805bd954bbc55ae437
7
+ data.tar.gz: 4cbf18ed39352bbe33637afa11bbd356a4a0c443583344333144a5a7c6babf3b2f799ac66c1c77b1998e43d9663f679ee0311322df27f580a9236d3fc4f50632
@@ -18,6 +18,7 @@
18
18
  require 'date'
19
19
  require 'bank_statement_parser/base'
20
20
  require 'bank_statement_parser/statement_record'
21
+ require 'bank_statement_parser/statement_record_types'
21
22
  require 'bank_statement_parser/utils'
22
23
  module BankStatementParser
23
24
 
@@ -112,8 +113,22 @@ module BankStatementParser
112
113
 
113
114
  private
114
115
 
115
- TYPES = ["ATM", "BP", "CHQ", "CIR", "CR", "DD", "DIV", "DR",
116
- "MAE", "PIM", "SO", "TFR", "VIS", ")))"]
116
+ TYPES = {
117
+ 'ATM' => StatementRecordTypes::ATM,
118
+ 'BP' => StatementRecordTypes::BILL_PAYMENT,
119
+ 'CHQ' => StatementRecordTypes::CHEQUE,
120
+ 'CIR' => StatementRecordTypes::CIRRUS,
121
+ 'CR' => StatementRecordTypes::CREDIT,
122
+ 'DD' => StatementRecordTypes::DIRECT_DEBIT,
123
+ 'DIV' => StatementRecordTypes::DIVIDEND,
124
+ 'DR' => StatementRecordTypes::DEBIT,
125
+ 'MAE' => StatementRecordTypes::MAESTRO,
126
+ 'PIM' => StatementRecordTypes::PAYING_IN_MACHINE,
127
+ 'SO' => StatementRecordTypes::STANDING_ORDER,
128
+ 'TFR' => StatementRecordTypes::TRANSFER,
129
+ 'VIS' => StatementRecordTypes::VISA,
130
+ ')))' => StatementRecordTypes::CONTACTLESS,
131
+ }
117
132
 
118
133
  MONTHS = Date::MONTHNAMES[1..12]
119
134
 
@@ -371,7 +386,7 @@ module BankStatementParser
371
386
  end
372
387
 
373
388
  payment_details = nil
374
- if payment_type_and_details =~ /\A(?<payment_type>#{TYPES.map{ |t| Regexp.quote(t) }.join('|')})\s+(?<payment_details>.*)\z/
389
+ if payment_type_and_details =~ /\A(?<payment_type>#{TYPES.keys.map{ |t| Regexp.quote(t) }.join('|')})\s+(?<payment_details>.*)\z/
375
390
  logger.debug { "Found the start of a record (group)" }
376
391
  @cached_payment_type = Regexp.last_match(:payment_type)
377
392
  payment_details = Regexp.last_match(:payment_details)
@@ -399,6 +414,7 @@ module BankStatementParser
399
414
  # Create statement record
400
415
  record = StatementRecord.new(date: @cached_statement_date,
401
416
  type: @cached_payment_type,
417
+ record_type: TYPES[@cached_payment_type],
402
418
  credit: record_credit,
403
419
  amount: record_amount,
404
420
  detail: full_details,
@@ -16,19 +16,28 @@
16
16
  # along with bank_statement_parser. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  require 'yaml'
19
+ require 'bank_statement_parser/statement_record_types'
19
20
 
20
21
  module BankStatementParser
21
22
 
22
23
  # A bank statement record
23
24
  class StatementRecord
24
- attr_accessor :date, :type, :credit, :amount, :detail, :balance
25
+ attr_accessor :date, :type, :record_type, :credit, :amount, :detail, :balance
25
26
 
26
27
  # Constructor
27
- def initialize date: nil, type: nil, credit: nil, amount: nil, detail: nil,
28
+ def initialize date: nil, type: nil, record_type: nil, credit: nil, amount: nil, detail: nil,
28
29
  balance: nil
29
30
 
31
+ # Sanity check the record type parameter
32
+ known_record_types = StatementRecordTypes.constants(false).map do |k|
33
+ StatementRecordTypes.const_get(k, false)
34
+ end
35
+ raise "Unknown statement record type #{record_type}" unless
36
+ known_record_types.include?(record_type)
37
+
30
38
  @date = date
31
39
  @type = type
40
+ @record_type = record_type
32
41
  @credit = credit
33
42
  @amount = amount
34
43
  @detail = detail
@@ -44,6 +53,7 @@ module BankStatementParser
44
53
  def ==(other)
45
54
  super || (date == other.date &&
46
55
  type == other.type &&
56
+ record_type == other.record_type &&
47
57
  credit == other.credit &&
48
58
  amount == other.amount &&
49
59
  detail == other.detail &&
@@ -0,0 +1,39 @@
1
+ # Copyright 2015 Simon Dawson <spdawson@gmail.com>
2
+
3
+ # This file is part of bank_statement_parser.
4
+ #
5
+ # bank_statement_parser is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # bank_statement_parser is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with bank_statement_parser. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module BankStatementParser
19
+
20
+ # Constants to enumerate bank statement record types
21
+ module StatementRecordTypes
22
+ ATM = :atm
23
+ BILL_PAYMENT = :bill_payment
24
+ CHEQUE = :cheque
25
+ CIRRUS = :cirrus
26
+ CREDIT = :credit
27
+ DIRECT_DEBIT = :direct_debit
28
+ DIVIDEND = :dividend
29
+ DEBIT = :debit
30
+ INTEREST = :interest
31
+ MAESTRO = :maestro
32
+ PAYING_IN_MACHINE = :paying_in_machine
33
+ STANDING_ORDER = :standing_order
34
+ TRANSFER = :transfer
35
+ VISA = :visa
36
+ CONTACTLESS = :contactless
37
+ end
38
+
39
+ end
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: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Dawson
@@ -39,6 +39,7 @@ files:
39
39
  - lib/bank_statement_parser/base.rb
40
40
  - lib/bank_statement_parser/hsbc.rb
41
41
  - lib/bank_statement_parser/statement_record.rb
42
+ - lib/bank_statement_parser/statement_record_types.rb
42
43
  - lib/bank_statement_parser/utils.rb
43
44
  homepage: https://github.com/spdawson/bank_statement_parser
44
45
  licenses: