bankline_csv_import_file 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66e997668b73970bc4435e68a9151d949bec1547
4
+ data.tar.gz: 285e3b7f92f5d1406434a8d8ce937e9862ee7920
5
+ SHA512:
6
+ metadata.gz: c4fe98dc2e53dbd8fd4932073ee28ba4e81d8fa19c66dcfd87bbc5094a6a837ac89154ddf4162d906a7abb32134e2bf4c0ed1d7ae8f2e620cfb012d41f104593
7
+ data.tar.gz: ab835ab9aa6e9c6fe4e2c5b3ad4d03bc178ccaf130837e6ec268bd2b70fdaf05b92e062911926b5e7f5ab0089b879a8cdbf40a90f43578cb4c3c3e45aa0fa5a3
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.3
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in bankline_csv_import_file.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bankline_csv_import_file (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.7.0)
12
+ rspec-core (~> 3.7.0)
13
+ rspec-expectations (~> 3.7.0)
14
+ rspec-mocks (~> 3.7.0)
15
+ rspec-core (3.7.1)
16
+ rspec-support (~> 3.7.0)
17
+ rspec-expectations (3.7.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.7.0)
20
+ rspec-mocks (3.7.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-support (3.7.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bankline_csv_import_file!
30
+ bundler (~> 1.16)
31
+ rake (~> 10.0)
32
+ rspec
33
+
34
+ BUNDLED WITH
35
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Auctionet.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Bankline CSV import file
2
+
3
+ Generate Bankline CSV import files per <https://www.business.rbs.co.uk/content/dam/rbs_co_uk/Business_and_Content/PDFs/Bankline/Bankline-import-file-guide-CSV-RBS.pdf>, used e.g. by NatWest.
4
+
5
+ Not intended to be a complete implementation. We have implemented what we need; feel free to make PRs for further behaviour.
6
+
7
+ USER BEWARE: At the time of writing, we have not yet verified that the produced file works.
8
+
9
+
10
+ ## Usage
11
+
12
+ ### Standard domestic payment
13
+
14
+ All these fields are required unless stated.
15
+
16
+ Currency will be assumed to be GBP.
17
+
18
+ file = BanklineCsvImportFile.new
19
+ file.add_domestic_payment(
20
+ payer_sort_code: "151000", # Any non-digits will be stripped automatically.
21
+ payer_account_number: "31806542", # Any non-digits will be stripped automatically.
22
+ amount: "123.45", # Strings and BigDecimal are allowed. (Floats are not advisable for money.)
23
+ beneficiary_sort_code: "151000", # Any non-digits will be stripped automatically.
24
+ beneficiary_account_number: "44298801", # Any non-digits will be stripped automatically.
25
+ beneficiary_name: "John Doe",
26
+ beneficiary_reference: "Invoice 123",
27
+ payment_date: Date.new(2018, 1, 1), # Optional. Defaults to Date.current if available, otherwise Date.today.
28
+ )
29
+ file.generate # => "foo,bar,…"
30
+
31
+ ### Payment templates, CHAPS, international payments
32
+
33
+ Not currently supported. Pull requests welcome!
34
+
35
+
36
+ ## Installation
37
+
38
+ Add this line to your application's Gemfile:
39
+
40
+ ```ruby
41
+ gem "bankline_csv_import_file"
42
+ ```
43
+
44
+ And then execute:
45
+
46
+ $ bundle
47
+
48
+ Or install it yourself as:
49
+
50
+ $ gem install bankline_csv_import_file
51
+
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
9
+ rescue LoadError
10
+ # no RSpec available
11
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "bankline_csv_import_file/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "bankline_csv_import_file"
9
+ spec.version = BanklineCsvImportFile::VERSION
10
+ spec.authors = ["Henrik Nyh"]
11
+ spec.email = ["henrik@nyh.se"]
12
+
13
+ spec.summary = %q{Generate Bankline CSV import files.}
14
+ spec.homepage = "https://github.com/barsoom/bankline_csv_import_file"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bankline_csv_import_file"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,54 @@
1
+ require "bankline_csv_import_file/version"
2
+ require "bankline_csv_import_file/record"
3
+
4
+ require "bigdecimal"
5
+ require "csv"
6
+
7
+ class BanklineCsvImportFile
8
+ def initialize
9
+ @records = []
10
+ end
11
+
12
+ def add_domestic_payment(payer_sort_code:, payer_account_number:, amount:, beneficiary_sort_code:, beneficiary_account_number:, beneficiary_name:, beneficiary_reference:, payment_date: nil)
13
+ # Use Ruby on Rails' `Date.current` when available, since it will be in the app time zone rather than the server time zone.
14
+ payment_date ||= Date.respond_to?(:current) ? Date.current : Date.today
15
+ formatted_payment_date = payment_date.strftime("%d%m%Y")
16
+
17
+ payer_account_with_sort_code = normalize_account("#{payer_sort_code}#{payer_account_number}")
18
+
19
+ record = Record.new
20
+
21
+ # https://www.business.rbs.co.uk/content/dam/rbs_co_uk/Business_and_Content/PDFs/Bankline/Bankline-import-file-guide-CSV-RBS.pdf
22
+ # Section 4.2, page 46.
23
+ record["T001"] = "01" # 01 = Standard domestic payment.
24
+ record["T010"] = payer_account_with_sort_code
25
+ record["T014"] = sprintf("%.2f", BigDecimal(amount))
26
+ record["T016"] = formatted_payment_date
27
+ record["T022"] = normalize_account(beneficiary_sort_code)
28
+ record["T028"] = normalize_account(beneficiary_account_number)
29
+ record["T030"] = normalize_string(beneficiary_name, max_length: 35)
30
+ record["T034"] = normalize_string(beneficiary_reference, max_length: 18)
31
+
32
+ @records << record
33
+ end
34
+
35
+ def generate
36
+ CSV.generate do |csv|
37
+ @records.each do |record|
38
+ csv << record.to_csv
39
+ end
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def normalize_account(string)
46
+ string.gsub(/\D/, "")
47
+ end
48
+
49
+ def normalize_string(string, max_length:)
50
+ output = string.to_s.upcase
51
+ output = output.gsub(%r{[^A-Z0-9./& -]}, "")
52
+ output[0, max_length]
53
+ end
54
+ end
@@ -0,0 +1,26 @@
1
+ class BanklineCsvImportFile
2
+ class Record
3
+ def initialize
4
+ # H001..H003, T001..T082.
5
+ @array = Array.new(85)
6
+ end
7
+
8
+ def []=(key, value)
9
+ case key
10
+ when "H001" then @array[0] = value
11
+ when "H002" then @array[1] = value
12
+ when "H003" then @array[2] = value
13
+ when /\AT(\d\d\d)\z/
14
+ i = $1.to_i
15
+ raise "Out of range!" unless (1..82).cover?(i)
16
+ @array[i + 2] = value
17
+ else
18
+ raise "Unknown field: #{key.inspect}"
19
+ end
20
+ end
21
+
22
+ def to_csv
23
+ @array
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ class BanklineCsvImportFile
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bankline_csv_import_file
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Henrik Nyh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - henrik@nyh.se
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bankline_csv_import_file.gemspec
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/bankline_csv_import_file.rb
74
+ - lib/bankline_csv_import_file/record.rb
75
+ - lib/bankline_csv_import_file/version.rb
76
+ homepage: https://github.com/barsoom/bankline_csv_import_file
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.6.11
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Generate Bankline CSV import files.
100
+ test_files: []