Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed deprecated code #24

Merged
merged 2 commits into from
Jun 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
### 0.3.5 (unreleased)
### (unreleased)

- Removed deprecated class `SwiftBic::BankDb` in favor of `Ibanizator::BankDb`
- Removed deprecated method `Iban::Validator.validate_iban` in favor of `Ibanizator.iban_from_string(iban).valid?`
- Removed deprecated method `Ibanizator.new.validate_iban(iban)` in favor of `Ibanizator.iban_from_string(iban).valid?`
- Removed deprecated method `Ibanizator.new.bic(bank_code)` in favor of `Ibanizator::BankDb.new.bank_by_bank_code(bank_code).bic`
- Removed deprecated method `Ibanizator.new.bank_name(bank_code)` in favor of `Ibanizator::BankDb.new.bank_by_bank_code(bank_code).bank_name`

### 0.3.5

- Updated blz.txt (valid until 02.09.2018)
- Fixed test suite
Expand Down
8 changes: 0 additions & 8 deletions lib/iban/validator.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
module Iban
class Validator
# <b>DEPRECATED:</b> Please use <tt>Ibanizator.iban_from_string(an_iban).valid?</tt> instead.
def validate_iban(input)
warn "[DEPRECATION] `Iban#validate_iban` is deprecated. Please use `Ibanizator.iban_from_string(an_iban).valid?instead."
iban = sanitize_input(input)

valid_length?(iban) && valid_checksum?(iban)
end

# public because it's used in `Ibanizator.calculate_iban`
def sanitize_input(input)
input.to_s.chomp.gsub(/\s+/,"")
Expand Down
36 changes: 8 additions & 28 deletions lib/ibanizator.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# frozen_string_literal: true

require_relative 'iban/validator'
require_relative 'swift_bic/bank_db'

require_relative 'ibanizator/bank_db'
require_relative 'ibanizator/bank'
require_relative 'ibanizator/iban'

class Ibanizator

def self.bank_db
@bank_db ||= BankDb.new
end

def self.iban_from_string(a_string)
Iban.from_string(a_string)
def self.iban_from_string(string)
Iban.from_string(string)
end

def calculate_iban options
def calculate_iban(options)
# Error handling
# TODO

Expand All @@ -34,34 +34,14 @@ def calculate_iban options
options[:country_code].to_s.upcase + checksum + options[:bank_code] + options[:account_number]
end

# <b>DEPRECATED:</b> Please use <tt>Ibanizator.iban_from_string(an_iban).valid?</tt> instead.
def validate_iban iban
warn "[DEPRECATION] `Ibanizator#validate_iban` is deprecated. Please use `Ibanizator.iban_from_string(an_iban).valid?instead."
# for the sake of compatibility
self.class.iban_from_string(iban).valid?
end

# <b>DEPRECATED:</b> Please use <tt>Ibanizator.bank_db.bank_by_bank_code</tt> instead.
def bic bank_code
warn "[DEPRECATION] `Ibanizator#bank_name` is deprecated. Please use `Ibanizator::bank_db.bank_by_bank_code` instead."
bank_db = SwiftBic::BankDb.new bank_code
bank_db.bic
end

# <b>DEPRECATED:</b> Please use <tt>Ibanizator.bank_db.bank_by_bank_code</tt> instead.
def bank_name bank_code
warn "[DEPRECATION] `Ibanizator#bank_name` is deprecated. Please use `Ibanizator::bank_db.bank_by_bank_code` instead."
bank_db = SwiftBic::BankDb.new bank_code
bank_db.bank_name
end

def character_to_digit char
def character_to_digit(char)
char.upcase.split('').inject('') { |code, c| code + (c.ord - 55).to_s }
end

def calculate_checksum bank_code, account_number, country_code_num
def calculate_checksum(bank_code, account_number, country_code_num)
x = (bank_code + account_number + country_code_num + '00').to_i % 97
checksum = (98 - x).to_s

checksum.length == 1 ? checksum.insert(0, '0') : checksum
end
end
40 changes: 0 additions & 40 deletions lib/swift_bic/bank_db.rb

This file was deleted.

48 changes: 0 additions & 48 deletions spec/iban/validator_spec.rb

This file was deleted.

86 changes: 31 additions & 55 deletions spec/ibanizator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

describe Ibanizator do
Expand Down Expand Up @@ -55,87 +57,61 @@
end
end

describe '#validate_iban' do
describe '#character_to_digit' do
context 'given :de as country code' do
it 'calculates 1314 as numeral country code' do
expect(ibanizator.character_to_digit('de')).to eq('1314')
end
end
end

describe '.bank_db' do
it 'returns a BankDB' do
expect(Ibanizator.bank_db).to be_a(Ibanizator::BankDb)
end
end

describe '.iban_from_string' do
it 'returns an Ibanizator::Iban' do
expect(Ibanizator.iban_from_string('an_iban')).to be_a(Ibanizator::Iban)
end

it 'delegates the object construction to Ibanizator::Iban.from_string' do
expect(Ibanizator::Iban).to receive(:from_string).with('a_string')

Ibanizator.iban_from_string('a_string')
end

context 'given valid iban' do
let(:iban) { 'DE58123456780123456789' }

it 'returns true' do
expect(ibanizator.validate_iban(iban)).to eq(true)
expect(Ibanizator.iban_from_string(iban).valid?).to eq(true)
end
end

context 'given invalid iban' do
let(:iban) { 'DE13100000001234567890' }

it 'returns false' do
expect(ibanizator.validate_iban(iban)).to eq(false)
expect(Ibanizator.iban_from_string(iban).valid?).to eq(false)
end

context 'given invalid country code' do
let(:iban) { 'XX13100000001234567890' }

it 'returns false' do
expect(ibanizator.validate_iban(iban)).to eq(false)
expect(Ibanizator.iban_from_string(iban).valid?).to eq(false)
end
end

context 'given invalid length' do
let(:iban) { 'DE13100000001234567' }

it 'returns false' do
expect(ibanizator.validate_iban(iban)).to eq(false)
expect(Ibanizator.iban_from_string(iban).valid?).to eq(false)
end
end
end
end

describe '#bic' do
before :each do
allow(SwiftBic::BankDb).to receive(:new).and_return(double('a bank', :bic => 'MARKDEF1100'))
end

describe 'given valid german bank code' do
it 'returns the bic' do
expect(ibanizator.bic('10000000')).to eq('MARKDEF1100')
end
end
end

describe '#bank_name' do
before :each do
allow(SwiftBic::BankDb).to receive(:new).and_return(double('a bank', :bic => 'BBk Berlin'))
end

describe 'given valid german bank code' do
it 'returns the bank name' do
expect(ibanizator.bic('10000000')).to eq('BBk Berlin')
end
end
end

describe '#character_to_digit' do
context 'given :de as country code' do
it 'calculates 1314 as numeral country code' do
expect(ibanizator.character_to_digit('de')).to eq('1314')
end
end
end

describe '.bank_db' do
it 'returns a BankDB' do
expect(Ibanizator.bank_db).to be_a(Ibanizator::BankDb)
end
end

describe '.iban_from_string(a_string)' do
it 'returns an Ibanizator::Iban' do
expect(Ibanizator.iban_from_string('an_iban')).to be_a(Ibanizator::Iban)
end

it 'delegates the object construction to Ibanizator::Iban.from_string' do
expect(Ibanizator::Iban).to receive(:from_string).with('a_string')

Ibanizator.iban_from_string('a_string')
end
end
end
44 changes: 0 additions & 44 deletions spec/swift_bic/bank_db_spec.rb

This file was deleted.