Class: Valabn::Utils
- Inherits:
-
Object
- Object
- Valabn::Utils
- Defined in:
- lib/valabn/utils.rb
Class Method Summary collapse
Class Method Details
.valid_format?(number) ⇒ Boolean
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/valabn/utils.rb', line 3 def self.valid_format?(number) number = number.to_s.gsub(/\W/, '') if !!( number =~ /\A[0-9]{11}\z/) weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19] sum = 0 numbers = number.split('').map(&:to_i) numbers[0] = numbers[0] - 1 numbers = numbers.zip(weights).map { |x, y| x * y } sum = numbers.inject(0, :+) (sum % 89).zero? else false end end |