Skip to content

Instantly share code, notes, and snippets.

@genee19
Created February 18, 2015 17:58
Show Gist options
  • Save genee19/c10f072c87480f1848c3 to your computer and use it in GitHub Desktop.
Save genee19/c10f072c87480f1848c3 to your computer and use it in GitHub Desktop.
Проверка валидности ИНН юрлица на Ruby (согласно http://www.egrul.ru/test_inn.html)
def valid_le_tax_id? (tax_id)
tax_id = tax_id.to_s.split('')
weights = [2,4,10,3,5,9,4,6,8,0]
sum = tax_id.each_with_index.reduce(0){|result,item|
result += item[0].to_i * weights[item[1]]
}%11%10
return sum == tax_id[9].to_i
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment