aba 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e304f03903a8b1cb21d29421192a35c2a8871bf
4
- data.tar.gz: fb95004c3d622d371e5402d754b3892cc1b2434c
3
+ metadata.gz: 7db46f198fd52a43b83a85c383db00bb9c1f6c0a
4
+ data.tar.gz: cfbf7860f3f136ee259c494fe88b0015c3a9d233
5
5
  SHA512:
6
- metadata.gz: 317b8b821976c27476a74dfa084563e8245908d31a4d1c9caaea3c4ef1fb7d80543147ef1a6c258adfbd8f405620480159668d9035c40d66a5530f1ef1a482fe
7
- data.tar.gz: c71f432a1bde06cd05630a7e9b4fefaf0d16230c96c2a70bfd2b99f89dc63faddeeb7e6140692419d09307bbc13689ffa6b5ba86ecb5435f1f8f7a903ae803a0
6
+ metadata.gz: 3166c7bbe642707defa8e890f915de79813e07a264d07a77c2c5a5053fce053724a2956c3627b4d0e484ea9f52613c11cacf1a5f1f3161936ef10e9790398a7a
7
+ data.tar.gz: 4cfdf45552802bcd767524524602eabcf816695b39fe1f3ade9953c2e43fdb054934adaeffa028a6dd35d546545932629d44c956bd5d469cd07b74c2841bc7e8
data/README.md CHANGED
@@ -1,32 +1,43 @@
1
+ [ ![Codeship Status for krakendevelopments/aba](https://codeship.com/projects/982382f0-f22b-0132-a80d-0acc257ded9c/status?branch=master)](https://codeship.com/projects/85083)
2
+
1
3
  # Aba
2
4
 
3
- The purpose of this gem is to generate an ABA (Australian Banking Association) file. It is a format used by banks to allow for batch transaction.
5
+ Generates ABA (Australian Banking Association) file format output
4
6
 
5
7
  ## Usage
6
8
 
7
9
  ```ruby
8
10
  require 'aba'
9
11
 
10
- aba = Aba.new(bsb: "123-345", financial_institution: "WPC", user_name: "John Doe",
11
- user_id: "466364", description: "Payroll", process_at: Time.now)
12
+ # Initialise ABA
13
+ aba = Aba.new(
14
+ bsb: "123-345", # Optional (Not required by NAB)
15
+ financial_institution: "WPC",
16
+ user_name: "John Doe",
17
+ user_id: "466364",
18
+ description: "Payroll",
19
+ process_at: Time.now.strftime("%d%m%y")
20
+ )
12
21
 
13
22
  # Add transactions
14
- transactions.each do |t|
15
- aba.transactions << Aba::Transaction.new(
16
- :bsb => "342-342",
17
- :account_number => "3244654",
18
- :amount => amount,
19
- :account_name => "John Doe",
20
- :payment_id => "P2345543",
21
- :transaction_code => 53,
22
- :lodgement_reference => "R435564",
23
- :trace_bsb => "453-543",
24
- :trace_account_number => "45656733",
25
- :name_of_remitter => "Remitter"
23
+ 10.times do
24
+ aba.add_transaction(
25
+ Aba::Transaction.new(
26
+ bsb: "342-342",
27
+ account_number: "3244654",
28
+ amount: 10000, # Amount in cents
29
+ account_name: "John Doe",
30
+ transaction_code: 53,
31
+ lodgement_reference: "R435564",
32
+ trace_bsb: "453-543",
33
+ trace_account_number: "45656733",
34
+ name_of_remitter: "Remitter"
35
+ )
26
36
  )
27
37
  end
28
38
 
29
- puts aba.to_s
39
+ puts aba.to_s # View output
40
+ File.write("/Users/me/dd_#{Time.now.to_i}.aba", aba.to_s) # or write output to file
30
41
  ```
31
42
 
32
43
  ## Installation
@@ -6,8 +6,8 @@ require 'aba/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "aba"
8
8
  spec.version = Aba::VERSION
9
- spec.authors = ["Andrey Bazhutkin"]
10
- spec.email = ["andrey.bazhutkin@gmail.com"]
9
+ spec.authors = ["Andrey Bazhutkin", "Trevor Wistaff"]
10
+ spec.email = ["andrey.bazhutkin@gmail.com", "trev@a07.com.au"]
11
11
  spec.summary = "ABA File Generator"
12
12
  spec.description = "ABA (Australian Bankers Association) File Generator"
13
13
  spec.homepage = "https://github.com/andrba/aba"
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
- spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rake", "~> 10.4"
23
+ spec.add_development_dependency "pry", "~> 0.10"
23
24
  spec.add_development_dependency "rspec", "~> 3.0"
24
25
 
25
26
  spec.required_ruby_version = '>= 1.9.2'
data/lib/aba.rb CHANGED
@@ -5,25 +5,23 @@ require "aba/transaction"
5
5
  class Aba
6
6
  include Aba::Validations
7
7
 
8
- attr_accessor :bsb, :account_number, :financial_institution, :user_name, :user_id,
9
- :description, :process_at, :name_of_remitter, :transactions
8
+ attr_accessor :bsb, :financial_institution, :user_name, :user_id, :description, :process_at
10
9
 
11
- validates_presence_of :bsb, :financial_institution, :user_name, :user_id, :description, :process_at
12
-
13
- validates_bsb :bsb
10
+ validates_bsb :bsb, allow_blank: true
14
11
 
15
- validates_max_length :account_number, 9
16
- validates_max_length :financial_institution, 3
17
12
  validates_max_length :user_name, 26
18
13
  validates_max_length :user_id, 6
19
14
  validates_max_length :description, 12
20
15
 
16
+ validates_length :financial_institution, 3
17
+ validates_length :process_at, 6
18
+
21
19
  def initialize(attrs = {})
22
20
  attrs.each do |key, value|
23
21
  send("#{key}=", value)
24
22
  end
25
23
 
26
- self.transactions = []
24
+ @transactions = []
27
25
 
28
26
  yield self if block_given?
29
27
  end
@@ -39,56 +37,70 @@ class Aba
39
37
  output += "\r\n#{batch_control_record}"
40
38
  end
41
39
 
40
+ def add_transaction(transaction)
41
+ @transactions << transaction
42
+ end
43
+
42
44
  private
43
45
 
44
46
  def descriptive_record
45
47
  # Record type
48
+ # Max: 1
49
+ # Char position: 1
46
50
  output = "0"
47
51
 
48
- # Bank/State/Branch number of the funds account with a hyphen in the 4th character position. e.g. 013-999.
49
- output += self.bsb
50
-
51
- # Funds account number.
52
- output += self.account_number.to_s.ljust(9, " ")
53
-
54
- # Reserved
55
- output += " "
52
+ # Optional branch number of the funds account with a hyphen in the 4th character position
53
+ # Char position: 2-18
54
+ # Max: 17
55
+ # Blank filled
56
+ output += self.bsb.nil? ? " " * 17 : self.bsb.to_s.ljust(17)
56
57
 
57
58
  # Sequence number
59
+ # Char position: 19-20
60
+ # Max: 2
61
+ # Zero padded
58
62
  output += "01"
59
63
 
60
- # Must contain the bank mnemonic that is associated with the BSB of the funds account. e.g. ‘ANZ’.
61
- output += self.financial_institution[0..2].to_s
64
+ # Name of user financial instituion
65
+ # Max: 3
66
+ # Char position: 21-23
67
+ output += self.financial_institution.to_s
62
68
 
63
69
  # Reserved
70
+ # Max: 7
71
+ # Char position: 24-30
64
72
  output += " " * 7
65
73
 
66
- # Name of User supplying File as advised by User's Financial Institution
67
- output += self.user_name.to_s.ljust(26, " ")
74
+ # Name of User supplying File
75
+ # Char position: 31-56
76
+ # Max: 26
77
+ # Blank filled
78
+ output += self.user_name.to_s.ljust(26)
68
79
 
69
- # Direct Entry User ID.
80
+ # Direct Entry User ID
81
+ # Char position: 57-62
82
+ # Max: 6
83
+ # Zero padded
70
84
  output += self.user_id.to_s.rjust(6, "0")
71
85
 
72
- # Description of payments in the file (e.g. Payroll, Creditors etc.).
73
- output += self.description.to_s.ljust(12, " ")
86
+ # Description of payments in the file (e.g. Payroll, Creditors etc.)
87
+ # Char position: 63-74
88
+ # Max: 12
89
+ # Blank filled
90
+ output += self.description.to_s.ljust(12)
74
91
 
75
- # Date and time on which the payment is to be processed.
76
- output += self.process_at.strftime("%d%m%y%H%M")
92
+ # Date on which the payment is to be processed
93
+ # Char position: 75-80
94
+ # Max: 6
95
+ output += self.process_at.rjust(6, "0")
77
96
 
78
97
  # Reserved
79
- output += " " * 36
98
+ # Max: 40
99
+ # Char position: 81-120
100
+ output += " " * 40
80
101
  end
81
102
 
82
103
  def batch_control_record
83
- # Record type
84
- output = "7"
85
-
86
- # BSB Format Filler
87
- output += "999-999"
88
-
89
- # Reserved
90
- output += " " * 12
91
-
92
104
  net_total_amount = 0
93
105
  credit_total_amount = 0
94
106
  debit_total_amount = 0
@@ -99,22 +111,49 @@ class Aba
99
111
  debit_total_amount += t.amount if t.amount < 0
100
112
  end
101
113
 
102
- # Must equal the difference between File Credit & File Debit Total Amounts. Show in cents without punctuation
114
+ # Record type
115
+ # Max: 1
116
+ # Char position: 1
117
+ output = "7"
118
+
119
+ # BSB Format Filler
120
+ # Max: 7
121
+ # Char position: 2-8
122
+ output += "999-999"
123
+
124
+ # Reserved
125
+ # Max: 12
126
+ # Char position: 9-20
127
+ output += " " * 12
128
+
129
+ # Net total
130
+ # Max: 10
131
+ # Char position: 21-30
103
132
  output += net_total_amount.abs.to_s.rjust(10, "0")
104
133
 
105
- # Batch Credit Total Amount
134
+ # Credit Total Amount
135
+ # Max: 10
136
+ # Char position: 31-40
106
137
  output += credit_total_amount.abs.to_s.rjust(10, "0")
107
138
 
108
- # Batch Debit Total Amount
139
+ # Debit Total Amount
140
+ # Max: 10
141
+ # Char position: 41-50
109
142
  output += debit_total_amount.abs.to_s.rjust(10, "0")
110
143
 
111
144
  # Reserved
145
+ # Max: 24
146
+ # Char position: 51-74
112
147
  output += " " * 24
113
148
 
114
- # Batch Total Item Count
149
+ # Total Item Count
150
+ # Max: 6
151
+ # Char position: 75-80
115
152
  output += @transactions.size.to_s.rjust(6, "0")
116
153
 
117
154
  # Reserved
155
+ # Max: 40
156
+ # Char position: 81-120
118
157
  output += " " * 40
119
158
  end
120
- end
159
+ end
@@ -2,14 +2,14 @@ class Aba
2
2
  class Transaction
3
3
  include Aba::Validations
4
4
 
5
- attr_accessor :account_number, :transaction_code, :amount, :account_name, :payment_id,
6
- :bsb, :trace_bsb, :trace_account_number, :name_of_remitter, :witholding_amount,
7
- :indicator, :lodgement_reference
5
+ attr_accessor :account_number, :transaction_code, :amount, :account_name,
6
+ :bsb, :trace_bsb, :trace_account_number, :name_of_remitter,
7
+ :witholding_amount, :indicator, :lodgement_reference
8
8
 
9
- validates_presence_of :bsb, :account_number, :amount, :account_name, :payment_id, :transaction_code,
10
- :lodgement_reference, :trace_bsb, :trace_account_number, :name_of_remitter
9
+ validates_bsb :bsb
10
+ validates_bsb :trace_bsb
11
11
 
12
- validates_bsb :bsb, :trace_bsb
12
+ validates_integer :amount
13
13
 
14
14
  validates_max_length :account_number, 9
15
15
  validates_max_length :indicator, 1
@@ -73,4 +73,4 @@ class Aba
73
73
  output += (witholding_amount || 0).abs.to_s.rjust(8, "0")
74
74
  end
75
75
  end
76
- end
76
+ end
@@ -1,4 +1,5 @@
1
1
  class Aba
2
+ require 'pry'
2
3
  module Validations
3
4
  attr_accessor :errors
4
5
 
@@ -22,9 +23,15 @@ class Aba
22
23
  when :presence
23
24
  self.errors << "#{attribute} is empty" if value.nil? || value.to_s.empty?
24
25
  when :bsb
25
- self.errors << "#{attribute} format is incorrect" unless value =~ /^\d{3}-\d{3}$/
26
+ unless((param && value.nil?) || value =~ /^\d{3}-\d{3}$/)
27
+ self.errors << "#{attribute} format is incorrect"
28
+ end
26
29
  when :max_length
27
30
  self.errors << "#{attribute} length must not exceed #{param} characters" if value.to_s.length > param
31
+ when :length
32
+ self.errors << "#{attribute} length must be exactly #{param} characters" if value.to_s.length != param
33
+ when :integer
34
+ self.errors << "#{attribute} must be an integer" unless value.to_s =~ /\A[+-]?\d+\Z/
28
35
  end
29
36
  end
30
37
  end
@@ -39,16 +46,23 @@ class Aba
39
46
  end
40
47
  end
41
48
 
42
- def validates_bsb(*attributes)
43
- attributes.each do |a|
44
- add_validation_attribute(a, :bsb)
45
- end
49
+ def validates_bsb(attribute, options = {})
50
+ options[:allow_blank] ||= false
51
+ add_validation_attribute(attribute, :bsb, options[:allow_blank])
46
52
  end
47
53
 
48
54
  def validates_max_length(attribute, length)
49
55
  add_validation_attribute(attribute, :max_length, length)
50
56
  end
51
57
 
58
+ def validates_length(attribute, length)
59
+ add_validation_attribute(attribute, :length, length)
60
+ end
61
+
62
+ def validates_integer(attribute)
63
+ add_validation_attribute(attribute, :integer)
64
+ end
65
+
52
66
  private
53
67
 
54
68
  def add_validation_attribute(attribute, type, param = true)
@@ -57,4 +71,4 @@ class Aba
57
71
  end
58
72
  end
59
73
  end
60
- end
74
+ end
@@ -1,3 +1,3 @@
1
1
  class Aba
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,40 +1,61 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Aba do
4
- subject(:aba) do
5
- aba = Aba.new(bsb: "123-345", financial_institution: "WPC", user_name: "John Doe",
6
- user_id: "466364", description: "Payroll", process_at: Time.new(2014, 12, 01, 10, 22, 0))
7
-
8
- [30, -20].each do |amount|
9
- aba.transactions << Aba::Transaction.new(
10
- :bsb => "342-342",
11
- :account_number => "3244654",
12
- :amount => amount,
13
- :account_name => "John Doe",
14
- :payment_id => "P2345543",
15
- :transaction_code => 53,
16
- :lodgement_reference => "R435564",
17
- :trace_bsb => "453-543",
18
- :trace_account_number => "45656733",
19
- :name_of_remitter => "Remitter"
20
- )
4
+ let(:aba) { Aba.new(financial_institution: "WPC", user_name: "John Doe",
5
+ user_id: "466364", description: "Payroll", process_at: "190615") }
6
+ let(:transaction_values) { [30, -20] }
7
+ let(:transactions) do
8
+ transaction_values.map do |amount|
9
+ Aba::Transaction.new(bsb: '342-342', account_number: '3244654', amount: amount,
10
+ account_name: 'John Doe', transaction_code: 53,
11
+ lodgement_reference: 'R435564', trace_bsb: '453-543',
12
+ trace_account_number: '45656733', name_of_remitter: 'Remitter')
21
13
  end
22
-
23
- aba
24
14
  end
15
+ subject { aba }
16
+ before { transactions.each { |trx| subject.add_transaction(trx) } }
25
17
 
26
18
  describe "#to_s" do
27
- it "should contain a descriptive record" do
28
- expect(subject.to_s).to include("0123-345 01WPC John Doe 466364Payroll 0112141022 \r\n")
19
+
20
+ context 'when descriptive record' do
21
+
22
+ context 'without bsb' do
23
+ it "should return a string containing the descriptive record without the bsb" do
24
+ expect(subject.to_s).to include("0 01WPC John Doe 466364Payroll 190615 \r\n")
25
+ end
26
+ end
27
+
28
+ context 'with bsb' do
29
+ before { subject.bsb = "123-345" }
30
+ it "should return a string containing the descriptive record with the bsb" do
31
+ expect(subject.to_s).to include("0123-345 01WPC John Doe 466364Payroll 190615 \r\n")
32
+ end
33
+ end
29
34
  end
30
35
 
31
- it "should contain transactions records" do
32
- expect(subject.to_s).to include("1342-342 3244654 530000000030John Doe R435564 453-543 45656733Remitter 00000000\r\n")
33
- expect(subject.to_s).to include("1342-342 3244654 530000000020John Doe R435564 453-543 45656733Remitter 00000000\r\n")
36
+
37
+ context 'when detail record' do
38
+
39
+ it "should contain transactions records" do
40
+ expect(subject.to_s).to include("1342-342 3244654 530000000030John Doe R435564 453-543 45656733Remitter 00000000\r\n")
41
+ expect(subject.to_s).to include("1342-342 3244654 530000000020John Doe R435564 453-543 45656733Remitter 00000000\r\n")
42
+ end
34
43
  end
35
44
 
36
- it "should contain a batch control record" do
37
- expect(subject.to_s).to include("7999-999 000000001000000000300000000020 000002 ")
45
+ context 'when file total record' do
46
+
47
+ context 'with unbalanced transactions' do
48
+ it "should return a string wihere the net total is not zero" do
49
+ expect(subject.to_s).to include("7999-999 000000001000000000300000000020 000002 ")
50
+ end
51
+ end
52
+
53
+ context 'with balanced transactions' do
54
+ let(:transaction_values) { [30, 30, -60] }
55
+ it "should return a string where the net total is zero" do
56
+ expect(subject.to_s).to include("7999-999 000000000000000000600000000060 000003 ")
57
+ end
58
+ end
38
59
  end
39
60
  end
40
- end
61
+ end
@@ -6,7 +6,6 @@ describe Aba::Transaction do
6
6
  :transaction_code => 53,
7
7
  :amount => 50050,
8
8
  :account_name => "John Doe",
9
- :payment_id => "P30234",
10
9
  :bsb => "345-453",
11
10
  :witholding_amount => 87,
12
11
  :indicator => "W",
@@ -31,7 +30,7 @@ describe Aba::Transaction do
31
30
  it "should not be valid" do
32
31
  transaction_params.delete(:bsb)
33
32
  expect(subject.valid?).to eq false
34
- expect(subject.errors).to eq ["bsb is empty", "bsb format is incorrect"]
33
+ expect(subject.errors).to eq ["bsb format is incorrect"]
35
34
  end
36
35
  end
37
- end
36
+ end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Bazhutkin
8
+ - Trevor Wistaff
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-11-24 00:00:00.000000000 Z
12
+ date: 2015-06-15 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -28,16 +29,30 @@ dependencies:
28
29
  name: rake
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ">="
32
+ - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: '0'
34
+ version: '10.4'
34
35
  type: :development
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - ">="
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.4'
42
+ - !ruby/object:Gem::Dependency
43
+ name: pry
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.10'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
39
54
  - !ruby/object:Gem::Version
40
- version: '0'
55
+ version: '0.10'
41
56
  - !ruby/object:Gem::Dependency
42
57
  name: rspec
43
58
  requirement: !ruby/object:Gem::Requirement
@@ -55,6 +70,7 @@ dependencies:
55
70
  description: ABA (Australian Bankers Association) File Generator
56
71
  email:
57
72
  - andrey.bazhutkin@gmail.com
73
+ - trev@a07.com.au
58
74
  executables: []
59
75
  extensions: []
60
76
  extra_rdoc_files: []
@@ -94,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
110
  version: '0'
95
111
  requirements: []
96
112
  rubyforge_project:
97
- rubygems_version: 2.4.4
113
+ rubygems_version: 2.2.2
98
114
  signing_key:
99
115
  specification_version: 4
100
116
  summary: ABA File Generator