Skip to content

Instantly share code, notes, and snippets.

@rkleine
Last active May 23, 2018 12:11
Show Gist options
  • Save rkleine/046aaf78847515300f6d to your computer and use it in GitHub Desktop.
Save rkleine/046aaf78847515300f6d to your computer and use it in GitHub Desktop.
CUIT - CUIL
class Object
def valid_cuit?
number = self.to_s.gsub(/\D/, '').split('')
return if number.size != 11
numbers = %w(5 4 3 2 7 6 5 4 3 2)
result = 0;
9.times.each { |i| result += number[i].to_i * numbers[i].to_i }
result = result % 11
result = 11 - result
result = 0 if result == 11
result = 9 if result == 10
result == number[10].to_i
end
end
20311251407.valid_cuit? # => true
20311251405.valid_cuit? # => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment