class Bicvalidator::Bic

Attributes

bank[RW]
bic_code[RW]
branch[RW]
country[RW]
location[RW]

Public Class Methods

new(bic_str) click to toggle source
# File lib/bicvalidator/bic.rb, line 4
def initialize(bic_str) 
    ##strip reicht nicht denn strip entfernt nur leerzeichen vorne und hinten
    @bic_code = bic_str.strip.gsub(/\s+/, '').upcase
end

Public Instance Methods

errorcode() click to toggle source
# File lib/bicvalidator/bic.rb, line 8
def errorcode
  return if valid?
  return "BV0010" if !has_valid_lenght?
  return "BV0011" if !has_valid_format?
  return "BV0012" if !valid_country_code?
  return "BV0013" if !valid_location_code?
  return "BV0014" if !valid_branch_code?
end
eu?() click to toggle source
# File lib/bicvalidator/bic.rb, line 47
def eu?
  @eu ||= (valid? and Bicvalidator.eu_countries.include? country)
end
has_valid_format?() click to toggle source
# File lib/bicvalidator/bic.rb, line 25
def has_valid_format?
  !(@bic_code =~ bic_iso_format).nil?
end
has_valid_lenght?() click to toggle source
# File lib/bicvalidator/bic.rb, line 21
def has_valid_lenght?
   [8, 11].include? @bic_code.length     
end
non_eu?() click to toggle source
# File lib/bicvalidator/bic.rb, line 51
def non_eu?
  @non_eu ||= (valid? and !eu?)
end
sepa_scheme?() click to toggle source
# File lib/bicvalidator/bic.rb, line 55
def sepa_scheme?
  #es koennen auch laender am SEAP teilnhmen die nicht in de rEU sind, wie zb CH
  valid? and Bicvalidator.sepa_bic_countries.include? country
end
valid?() click to toggle source

in instanz

# File lib/bicvalidator/bic.rb, line 17
def valid?
  has_valid_lenght? && has_valid_format? && valid_country_code? && valid_location_code? && valid_branch_code?
end
valid_branch_code?() click to toggle source
# File lib/bicvalidator/bic.rb, line 40
def valid_branch_code?
  #Der Branch-Code darf nicht mit „X“ anfangen, es sei denn, es ist „XXX“.
  return true if @bic_code.length == 8
  return true if branch == "XXX"
  (branch[0] =~ /[X]/).nil?          
end
valid_country_code?() click to toggle source
# File lib/bicvalidator/bic.rb, line 29
def valid_country_code?
  Bicvalidator.countries.include? country
end
valid_location_code?() click to toggle source
# File lib/bicvalidator/bic.rb, line 33
def valid_location_code?
  #http://de.wikipedia.org/wiki/ISO_9362
  #2-stellige Codierung des Ortes in zwei Zeichen. Das erste Zeichen darf nicht die Ziffer „0“ oder „1“ sein.
  #Der Buchstabe 'O' ist als zweites Zeichen nicht gestattet.
  !(location[0] =~ /[^01]/ && location[1] =~ /[^O]/).nil?
end

Private Instance Methods

bic_iso_format() click to toggle source
# File lib/bicvalidator/bic.rb, line 79
def bic_iso_format
  #https://de.wikipedia.org/wiki/ISO_9362
  #BBBB 4-stelliger Bankcode, vom Geldinstitut frei wählbar
  #CC 2-stelliger Ländercode nach ISO 3166-1
  #LL 2-stellige Codierung des Ortes in zwei Zeichen.
    #Das erste Zeichen darf nicht die Ziffer „0“ oder „1“ sein.
    #Wenn das zweite Zeichen kein Buchstabe, sondern eine Ziffer ist, so bedeutet dies:
  #bbb 3-stellige Kennzeichnung (Branch-Code) der Filiale oder Abteilung (optional)
  #test in http://rubular.com/
  /([A-Z]{4})([A-Z]{2})([0-9A-Z]{2})([0-9A-Z]{3})?/
end
match() click to toggle source
# File lib/bicvalidator/bic.rb, line 91
def match
  bic_iso_format.match(@bic_code)
end