class Valvat::Checksum::BG

Public Instance Methods

build_prod(add = 1) click to toggle source
# File lib/valvat/checksum/bg.rb, line 48
def build_prod(add = 1)
  prod = 0
  figures.each_with_index do |fig, index|
    prod += (index + add) * fig.to_i
  end
  prod
end
check_digit() click to toggle source
# File lib/valvat/checksum/bg.rb, line 6
def check_digit
  natural_person? ? check_digit_natural_person : check_digit_legal_person
end
check_digit_foreign_natural_person() click to toggle source
# File lib/valvat/checksum/bg.rb, line 29
def check_digit_foreign_natural_person
  weight = [21, 19, 17, 13, 11, 9, 7, 3, 1]

  figures.map do |fig|
    fig * weight.shift
  end.inject(:+).modulo(10)
end
check_digit_local_natural_person() click to toggle source
# File lib/valvat/checksum/bg.rb, line 18
def check_digit_local_natural_person
  weight = [2, 4, 8, 5, 10, 9, 7, 3, 6]
  chk = figures.map do |fig|
    fig * weight.shift
  end.inject(:+).modulo(11)

  return chk if chk < 10

  0
end
check_digit_natural_person() click to toggle source
# File lib/valvat/checksum/bg.rb, line 10
def check_digit_natural_person
  local_person_chk = check_digit_local_natural_person

  return local_person_chk if given_check_digit == local_person_chk

  check_digit_foreign_natural_person
end
natural_person?() click to toggle source
# File lib/valvat/checksum/bg.rb, line 56
def natural_person?
  vat.to_s_wo_country.length == 10
end