Sha256: 6c26cbcb5ab0469cf5bac36b72b62f7066864e3d7461a5f6d4a6367d6957956c
Contents?: true
Size: 884 Bytes
Versions: 13
Compression:
Stored size: 884 Bytes
Contents
# http://sv.wikipedia.org/wiki/Bankgirot#Bankgironummer module BankTools module SE class Bankgiro attr_reader :number def initialize(number) @number = number end def valid? errors.empty? end def errors errors = [] errors << Errors::TOO_SHORT if digits.length < 7 errors << Errors::TOO_LONG if digits.length > 8 errors << Errors::INVALID_CHARACTERS if number.to_s.match(/[^0-9 -]/) errors << Errors::BAD_CHECKSUM unless Utils.valid_luhn?(number) errors end def normalize if valid? digits.split(/(\d{4})$/).join("-") else number end end def fundraising? valid? && digits.match(/\A90[0-4]/) end private def digits number.to_s.gsub(/\D/, '') end end end end
Version data entries
13 entries across 13 versions & 1 rubygems