polish_banks 1.0.2 → 1.1.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
  SHA256:
3
- metadata.gz: decff735a57bec8334fad408c498eadf29409a20b2354a7cb910fdb477a9b13c
4
- data.tar.gz: 38d61ccdc1f046abe281860746b8a06427b14fb0dd4cc9c28050a9b71e075bc1
3
+ metadata.gz: a97cbcce56873cba6b53f891adf2e52f659bdfa8c9e852b204738d03cd7352ad
4
+ data.tar.gz: 8908a1b4b6b6d8b6f79b1f0aa639747f9b21e71513b9d596b3027a5386ea36ac
5
5
  SHA512:
6
- metadata.gz: 67a612079cd5a4fac653ce5bea83a974aca9d3dcb4612615fd359087d73d216166c33bd871b546d7f15b21970e569221f3789460d80cbe8a0e214e979f59a5cc
7
- data.tar.gz: 0b35d22cf6156cfccdb269eadcdfa0f86d1bef719c1a66192a8d2e16cfdab9987ebd767bc3376f3716c2e61ae333d18701762d1129ff459e24d80d66269ae40e
6
+ metadata.gz: 456c01e8b6ac5287f47650bff89d2e8637172b44e6ca5989a8dbf6d29f064e24400de276dfb604a11da8b03ce8283b8d4eee5221a057d799b39c03dd55cd0ed9
7
+ data.tar.gz: bbc4ece64238ce6f33411d64e11b2d1d1b218e24ff0f6165751499c5bc98e76b67b94d43368d582c6da33e61e19b322af846435fb39aec839fb7295715a32f4f
data/.gitignore CHANGED
@@ -1 +1,4 @@
1
1
  lib/plewibnra.txt
2
+ lib/PlainDok.txt
3
+ Gemfile.lock
4
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # PolishBanks - A Polish bank lookup Ruby gem.
2
2
 
3
- Polish bank name and branch can be read from the IBAN or accont number.
3
+ Polish bank name and branch can be read from the IBAN or account number
4
4
 
5
5
  `PLkk BBBB BBBB MMMM MMMM MMMM MMMM`
6
6
 
@@ -28,13 +28,13 @@ Or install on your own to test it in irb:
28
28
 
29
29
  You can use either IBAN or just account number - as string or as integer. If you don't provide the whole account number, the gem will try to determine at least the bank name. Non-Polish ibans will raise a `UnsupportedCountry` exception.
30
30
 
31
- require 'credit_card_bins'
31
+ require 'polish_banks'
32
32
 
33
33
  iban = "PL9912406999"
34
34
  bank = PolishBank.new(iban)
35
35
 
36
- bank.name #"Bank Polska Kasa Opieki Spółka Akcyjna"
37
- bank.branch #"Oddział w Tychach ul. Wyszyńskiego 27"
36
+ bank.name # "Bank Polska Kasa Opieki Spółka Akcyjna"
37
+ bank.branch # "Oddział w Tychach ul. Wyszyńskiego 27"
38
38
 
39
39
  If bank is not found, the gem will raise a `BankNotFound` exception.
40
40
 
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/lib/data/6110.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ name: VIVA PAYMENT SERVICES SPÓŁKA AKCYJNA ODDZIAŁ W POLSCE
3
+ 61100006:
4
+ branch: Viva Payments Poland
data/lib/data/7003.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- name: Spółdzielcza Kasa Oszczędnościowo-Kredytowa KOZIENICE
2
+ name: Spółdzielcza Kasa Oszczędnościowo-Kredytowa ENERGIA
3
3
  70030006:
4
4
  branch: Centrala
data/lib/data/8441.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- name: Bank Spółdzielczy w Siewierzu
2
+ name: Krakowski Bank Spółdzielczy
3
3
  84410001:
4
4
  branch: Centrala
data/lib/data/8471.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- name: Bank Spółdzielczy Bytom
2
+ name: Krakowski Bank Spółdzielczy
3
3
  84710000:
4
4
  branch: Centrala
data/lib/data/9015.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  name: Bank Spółdzielczy w Starej Białej
3
3
  90150001:
4
- branch: Centrala
4
+ branch: Oddział
@@ -1,24 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  require 'fileutils'
2
4
  require 'yaml'
3
5
 
4
6
  BANK_NAME_COL = 1
5
7
  BRANCH_IDENTIFIER_COL = 4
6
8
  BRANCH_NAME_COL = 5
7
- DATA_DIR_NAME = 'data'.freeze
8
- FILE_NAME = 'plewibnra.txt'.freeze
9
+ DATA_DIR_NAME = 'data'
10
+ FILENAMES = ['plewibnra.txt', 'PlainDok.txt'].freeze
11
+
12
+ filename = FILENAMES.detect { |file| File.exist?(file) }
9
13
 
10
14
  FileUtils.mkdir_p(DATA_DIR_NAME) unless File.directory?(DATA_DIR_NAME)
11
15
 
12
- file = File.open(FILE_NAME, 'r', encoding: 'CP852')
16
+ file = File.open(filename, 'r', encoding: 'CP852')
13
17
 
14
18
  file.each_line do |row|
15
- row = row.encode(Encoding.find('UTF-8'), {invalid: :replace, undef: :replace, replace: ''}).split("\t").map(&:strip)
19
+ row = row.encode(Encoding.find('UTF-8'), invalid: :replace, undef: :replace, replace: '').split("\t").map(&:strip)
16
20
 
17
21
  branch_identifier = row[BRANCH_IDENTIFIER_COL]
18
22
  bank_identifier = branch_identifier.slice(0, 4)
19
23
  branch_name = row[BRANCH_NAME_COL]
20
24
 
21
- file_name = "#{DATA_DIR_NAME}/#{bank_identifier}.yml"
25
+ data_file = "#{DATA_DIR_NAME}/#{bank_identifier}.yml"
22
26
 
23
27
  content = {
24
28
  branch_identifier.to_i => {
@@ -26,19 +30,19 @@ file.each_line do |row|
26
30
  }
27
31
  }
28
32
 
29
- if File.exist?(file_name)
30
- yaml_string = File.read(file_name)
33
+ if File.exist?(data_file)
34
+ yaml_string = File.read(data_file)
31
35
  data = YAML.safe_load(yaml_string)
32
36
 
33
37
  content = data.merge(content)
34
38
  else
35
- File.new(file_name, 'w+')
39
+ File.new(data_file, 'w+')
36
40
 
37
41
  bank_name = row[BANK_NAME_COL].strip
38
42
  content = { 'name' => bank_name }.merge(content)
39
43
  end
40
44
 
41
- File.open(file_name, 'r+') do |f|
45
+ File.open(data_file, 'r+') do |f|
42
46
  f.write(content.to_yaml(line_width: -1))
43
47
  end
44
48
  end
data/lib/polish_banks.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'errors/bank_not_found'
3
5
  require 'errors/unsupported_country'
@@ -33,6 +35,7 @@ class PolishBank
33
35
 
34
36
  def check_country
35
37
  return if integer?(country_code)
38
+
36
39
  raise UnsupportedCountry, "Iban #{iban} is not Polish" if country_code.casecmp('PL') != 0
37
40
  end
38
41
 
data/polish_banks.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'polish_banks'
3
- s.version = '1.0.2'
4
- s.date = '2019-10-07'
3
+ s.version = '1.1.0'
4
+ s.date = '2019-10-19'
5
5
  s.summary = 'Polish bank detector'
6
6
  s.description = 'Get information about a Polish bank based on IBAN or account number.'
7
7
  s.authors = ['Maciej Czuchnowski']
@@ -9,4 +9,5 @@ Gem::Specification.new do |s|
9
9
  s.files = `git ls-files -z`.split("\x0")
10
10
  s.homepage = 'https://github.com/mczuchnowski/polish_banks'
11
11
  s.license = 'MIT'
12
+ s.add_development_dependency 'rspec', '~> 3.0'
12
13
  end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'polish_banks'
4
+
5
+ RSpec.describe PolishBank do
6
+ subject { described_class.new(iban) }
7
+
8
+ describe "standard iban check" do
9
+ let(:iban) { "PL9912406999" }
10
+
11
+ it "detects bank name" do
12
+ expect(subject.name).to be_a String
13
+ expect(subject.name.length).to be_positive
14
+ end
15
+
16
+ it "detects bank branch" do
17
+ expect(subject.branch).to be_a String
18
+ expect(subject.branch.length).to be_positive
19
+ end
20
+
21
+ context "with only partial match" do
22
+ let(:iban) { "PL9912406666" }
23
+
24
+ it "detects bank name" do
25
+ expect(subject.name).to be_a String
26
+ expect(subject.name.length).to be_positive
27
+ end
28
+
29
+ it "detects bank branch" do
30
+ expect(subject.branch).to be_a String
31
+ expect(subject.branch.length).to be_zero
32
+ end
33
+ end
34
+
35
+ context "with special characters" do
36
+ let(:iban) { "99-1240 6999" }
37
+
38
+ it "detects bank name" do
39
+ expect(subject.name).to be_a String
40
+ expect(subject.name.length).to be_positive
41
+ end
42
+
43
+ it "detects bank branch" do
44
+ expect(subject.branch).to be_a String
45
+ expect(subject.branch.length).to be_positive
46
+ end
47
+ end
48
+ end
49
+
50
+ describe "account number check" do
51
+ let(:iban) { "9912406999" }
52
+
53
+ it "detects bank name" do
54
+ expect(subject.name).to be_a String
55
+ expect(subject.name.length).to be_positive
56
+ end
57
+
58
+ it "detects bank branch" do
59
+ expect(subject.branch).to be_a String
60
+ expect(subject.branch.length).to be_positive
61
+ end
62
+ end
63
+
64
+ describe "error raising" do
65
+ context "foreign iban" do
66
+ let(:iban) { "DE9912406999" }
67
+
68
+ it "raises UnsupportedCountry error" do
69
+ expect { subject }.to raise_error(UnsupportedCountry, "Iban #{iban} is not Polish")
70
+ end
71
+ end
72
+
73
+ context "unknown bank" do
74
+ let(:iban) { "PL6666666666" }
75
+
76
+ it "raises BankNotFound error" do
77
+ expect { subject }.to raise_error(BankNotFound, "Polish bank not found for #{iban}")
78
+ end
79
+ end
80
+ end
81
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polish_banks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Czuchnowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-07 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2019-10-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
13
27
  description: Get information about a Polish bank based on IBAN or account number.
14
28
  email: maciej.czuchnowski@gmail.com
15
29
  executables: []
@@ -17,7 +31,9 @@ extensions: []
17
31
  extra_rdoc_files: []
18
32
  files:
19
33
  - ".gitignore"
34
+ - Gemfile
20
35
  - README.md
36
+ - Rakefile
21
37
  - lib/data/1010.yml
22
38
  - lib/data/1020.yml
23
39
  - lib/data/1030.yml
@@ -107,6 +123,7 @@ files:
107
123
  - lib/data/6000.yml
108
124
  - lib/data/6040.yml
109
125
  - lib/data/6070.yml
126
+ - lib/data/6110.yml
110
127
  - lib/data/6200.yml
111
128
  - lib/data/6300.yml
112
129
  - lib/data/7003.yml
@@ -369,7 +386,6 @@ files:
369
386
  - lib/data/8597.yml
370
387
  - lib/data/8600.yml
371
388
  - lib/data/8602.yml
372
- - lib/data/8606.yml
373
389
  - lib/data/8612.yml
374
390
  - lib/data/8614.yml
375
391
  - lib/data/8619.yml
@@ -733,6 +749,7 @@ files:
733
749
  - lib/errors/unsupported_country.rb
734
750
  - lib/polish_banks.rb
735
751
  - polish_banks.gemspec
752
+ - spec/polish_banks_spec.rb
736
753
  homepage: https://github.com/mczuchnowski/polish_banks
737
754
  licenses:
738
755
  - MIT
@@ -752,8 +769,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
752
769
  - !ruby/object:Gem::Version
753
770
  version: '0'
754
771
  requirements: []
755
- rubyforge_project:
756
- rubygems_version: 2.7.7
772
+ rubygems_version: 3.0.3
757
773
  signing_key:
758
774
  specification_version: 4
759
775
  summary: Polish bank detector
data/lib/data/8606.yml DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- name: Bank Spółdzielczy w Raciechowicach
3
- 86060006:
4
- branch: Centrala