class Viitenumero::RFViite
Note: Supports only ISO 11649 creditor references that are based on Finnish national reference numbers (see fi_viite). Does not support other SEPA countries.
Attributes
number[R]
Public Class Methods
generate(base, add_fi_checksum: true)
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 28 def self.generate(base, add_fi_checksum: true) base = (base || '').to_s.gsub(/\s+/, '') raise ArgumentError.new('must be a number') if base.match(/\A\d+\z/).nil? raise ArgumentError.new('must be between 3-19 chars long') if base.length < 3 || base.length > 19 base = base + FIViite.checksum(base) if add_fi_checksum RFViite.new('RF' + checksum(base) + base) end
new(s)
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 12 def initialize(s) @number = format(s) end
random(length: 8)
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 37 def self.random(length: 8) raise ArgumentError if length < 8 || length > 24 base_length = length - 4 FIViite.random(length: base_length).to_rf end
valid?(s)
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 43 def self.valid?(s) RFViite.new(s).valid? end
Private Class Methods
checksum(base)
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 82 def self.checksum(base) (98 - (base + '271500').to_i % 97).to_s.rjust(2, '0') end
Public Instance Methods
machine_format()
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 20 def machine_format number end
national_part()
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 55 def national_part number[4..-1] end
paper_format()
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 16 def paper_format number.gsub(/.{4}(?=.)/, '\0 ') end
to_fi()
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 51 def to_fi FIViite.new(national_part) end
to_s()
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 47 def to_s machine_format end
valid?()
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 24 def valid? valid_format? and valid_length? and valid_checksum? and valid_national_checksum? end
Private Instance Methods
format(s)
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 61 def format(s) (s || '').to_s.gsub(/\s+/, '').upcase end
valid_checksum?()
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 73 def valid_checksum? check_digits = number[2..3] check_digits == self.class.checksum(national_part) end
valid_format?()
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 65 def valid_format? !number.match(/\ARF\d+\z/).nil? end
valid_length?()
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 69 def valid_length? number.length >= 8 && number.length <= 24 end
valid_national_checksum?()
click to toggle source
# File lib/viitenumero/rf_viite.rb, line 78 def valid_national_checksum? FIViite.valid?(national_part) end