class ElfproefPlan::ElfProef
Attributes
letter[RW]
nr[RW]
nrs[RW]
subnr[RW]
Public Class Methods
new(input)
click to toggle source
# File lib/elfproef_plan.rb, line 27 def initialize(input) @nrs = (2..9).to_a.reverse @nr, @letter, @subnr = input.to_s.scan(/[0-9a-zA-Z+$]/).join().upcase().match(/([0-9]*)([A-Z]*)([0-9]*)/i).captures.map{|x| x.scan(/./)} @nr, @subnr = @nr.map{|x| x.to_i}, @subnr.map{|x| x.to_i} end
Public Instance Methods
validBsn()
click to toggle source
# File lib/elfproef_plan.rb, line 41 def validBsn return false if @nr.length > 9 @nr.unshift 0 while @nr.length < 9 return false if @nr[0,3].sum < 1 elfproef(-1) end
validLoonheffingennummer()
click to toggle source
# File lib/elfproef_plan.rb, line 48 def validLoonheffingennummer return false unless validBsn return false unless @letter==["L"] return false unless @subnr.reduce(:+)>0 true end
validRekening()
click to toggle source
# File lib/elfproef_plan.rb, line 35 def validRekening return false unless [9, 10].include? @nr.length @nrs.unshift 10 if @nr.length == 10 elfproef(1) end
Private Instance Methods
elfproef(b)
click to toggle source
# File lib/elfproef_plan.rb, line 60 def elfproef(b) @nrs.push b reeks = @nr.zip(@nrs) @nrs.pop som = reeks.inject(0){|som, x| som + (x[0]*x[1]) } som.remainder(11)==0 && som>0 end