sepa_clearer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ module SepaClearer
2
+ class Clearer
3
+ def initialize(clearer = 'DeutscheBundesbank')
4
+ @klass = SepaClearer.const_get(clearer).new
5
+ end
6
+
7
+ def all
8
+ @klass.data
9
+ end
10
+
11
+ def find_by_bic(bic)
12
+ normalized_bic = normalize_bic(bic)
13
+ @klass.data.find { |provider| provider.bic == normalized_bic }
14
+ end
15
+
16
+ def normalize_bic(bic)
17
+ bic.to_s.ljust(11, 'X').upcase
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ require 'csv'
2
+
3
+ module SepaClearer
4
+ class DeutscheBundesbank
5
+ CAPABILITIES_MAPPING = {
6
+ service_sct: :sct,
7
+ service_sdd: :core,
8
+ service_cor1: :cor1,
9
+ service_b2b: :b2b
10
+ }
11
+
12
+ def data(file = 'data/deutsche_bundesbank.csv')
13
+ @data ||= begin
14
+ [].tap do |data|
15
+ CSV.foreach(file, { headers: true, col_sep: ';', header_converters: :symbol }) do |row|
16
+ data.push PaymentProvider.new(*parse_raw_data(row))
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ def parse_raw_data(data)
23
+ [
24
+ data[:name].strip.chomp,
25
+ data[:bic],
26
+ CAPABILITIES_MAPPING.map { |key, service| data[key] == '1' ? service : nil }.compact
27
+ ]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ module SepaClearer
2
+ class PaymentProvider
3
+ SERVICES = [:sct, :core, :cor1, :b2b]
4
+
5
+ attr_accessor :name, :bic, :capabilities
6
+
7
+ def initialize(name, bic, capabilities)
8
+ self.name = name
9
+ self.bic = bic
10
+ self.capabilities = capabilities
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module SepaClearer
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'sepa_clearer/version'
2
+ require 'sepa_clearer/clearer'
3
+ require 'sepa_clearer/deutsche_bundesbank'
4
+ require 'sepa_clearer/payment_provider'
5
+
6
+ module SepaClearer
7
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sepa_clearer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sepa_clearer"
8
+ spec.version = SepaClearer::VERSION
9
+ spec.authors = ["Maximilian Schulz"]
10
+ spec.email = ["m.schulz@kulturfluss.de"]
11
+ spec.summary = %q{List of all available SEPA clearers and their supported features}
12
+ spec.description = %q{This gem maintains a list of all RPS SEPA clearers available via the Deutsche Bundesbank.}
13
+ spec.homepage = "http://opensource.railslove.com/sepa-clearer"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 0"
23
+ spec.add_development_dependency "rspec", "~> 3"
24
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe SepaClearer::Clearer do
4
+ describe '#all' do
5
+ it 'returns an array of payment providers' do
6
+ expect(subject.all.first).to be_kind_of(SepaClearer::PaymentProvider)
7
+ end
8
+ end
9
+
10
+ describe '#find_by_bic' do
11
+ it 'returns the provider with the given BIC' do
12
+ expect(subject.find_by_bic('AABAFI22TMS')).to be_kind_of(SepaClearer::PaymentProvider)
13
+ end
14
+
15
+ it 'returns nil if no object matches the BIC' do
16
+ expect(subject.find_by_bic('MYTHINGY')).to eq(nil)
17
+ end
18
+
19
+ it 'normalizes thebic before searching' do
20
+ allow(subject).to receive(:normalize_bic).and_return('AAA')
21
+ expect(subject.find_by_bic('MYTHINGY')).to eq(nil)
22
+ expect(subject).to have_received(:normalize_bic)
23
+ end
24
+ end
25
+
26
+ describe '#normalize_bic' do
27
+ it 'makes all letters uppercase' do
28
+ expect(subject.normalize_bic('lowercaseid')).to eq('LOWERCASEID')
29
+ end
30
+
31
+ it 'always uses 11 letter BICs' do
32
+ expect(subject.normalize_bic('SHORT')).to eq('SHORTXXXXXX')
33
+ end
34
+
35
+ it 'handles nil values' do
36
+ expect(subject.normalize_bic(nil)).to eq('XXXXXXXXXXX')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe SepaClearer::DeutscheBundesbank do
4
+ describe '#parse_raw_data' do
5
+ let(:data) { { name: "My Org \n", bic: 'QWERTZ12345', service_sct: '1' } }
6
+ it 'returns an array' do
7
+ expect(subject.parse_raw_data(data)).to eq(['My Org', 'QWERTZ12345', [:sct]])
8
+ end
9
+
10
+ it 'cleans up the name' do
11
+ expect(subject.parse_raw_data(data)[0]).to eq('My Org')
12
+ end
13
+
14
+ it 'returns the BIC' do
15
+ expect(subject.parse_raw_data(data)[1]).to eq('QWERTZ12345')
16
+ end
17
+
18
+ it 'maps the capabilities' do
19
+ expect(subject.parse_raw_data(data)[2]).to eq([:sct])
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe SepaClearer::PaymentProvider do
4
+ describe '.new' do
5
+ subject(:provider) { described_class.new('Testorg', 'SOMEVALIDID', [:core]) }
6
+
7
+ it 'sets the proper name' do
8
+ expect(provider.name).to eq('Testorg')
9
+ end
10
+
11
+ it 'sets the proper BIC' do
12
+ expect(provider.bic).to eq('SOMEVALIDID')
13
+ end
14
+
15
+ it 'sets the proper capabilities' do
16
+ expect(provider.capabilities).to eq([:core])
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ require 'sepa_clearer'
2
+
3
+ RSpec.configure do |config|
4
+ config.filter_run :focus
5
+ config.run_all_when_everything_filtered = true
6
+
7
+ if config.files_to_run.one?
8
+ config.default_formatter = 'doc'
9
+ end
10
+
11
+ config.profile_examples = 3
12
+
13
+ config.order = :random
14
+
15
+ Kernel.srand config.seed
16
+
17
+ config.expect_with :rspec do |expectations|
18
+ expectations.syntax = :expect
19
+ end
20
+
21
+ config.mock_with :rspec do |mocks|
22
+ mocks.syntax = :expect
23
+ mocks.verify_partial_doubles = true
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sepa_clearer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Maximilian Schulz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-16 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ description: This gem maintains a list of all RPS SEPA clearers available via the
56
+ Deutsche Bundesbank.
57
+ email:
58
+ - m.schulz@kulturfluss.de
59
+ executables:
60
+ - update_data
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/update_data
70
+ - data/deutsche_bundesbank.csv
71
+ - lib/sepa_clearer.rb
72
+ - lib/sepa_clearer/clearer.rb
73
+ - lib/sepa_clearer/deutsche_bundesbank.rb
74
+ - lib/sepa_clearer/payment_provider.rb
75
+ - lib/sepa_clearer/version.rb
76
+ - sepa-clearer.gemspec
77
+ - spec/clearer_spec.rb
78
+ - spec/deutsche_bundesbank_spec.rb
79
+ - spec/payment_provider_spec.rb
80
+ - spec/spec_helper.rb
81
+ homepage: http://opensource.railslove.com/sepa-clearer
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.2.2
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: List of all available SEPA clearers and their supported features
105
+ test_files:
106
+ - spec/clearer_spec.rb
107
+ - spec/deutsche_bundesbank_spec.rb
108
+ - spec/payment_provider_spec.rb
109
+ - spec/spec_helper.rb
110
+ has_rdoc: