Module: Weird

Defined in:
lib/weird.rb,
lib/weird/version.rb

Constant Summary collapse

FIRST_WEIGHTING =
[3, 2, 7, 6, 5, 4, 3, 2]
SECOND_WEIGHTING =
[7, 4, 3, 2, 5, 2, 7, 6]
VERSION =
'0.0.2'

Class Method Summary collapse

Class Method Details

.valid_ird?(input) ⇒ Boolean

Check digit validation The following steps are to be performed:

  • Valid range >10,000,000 & <150,000,000 (This will ensure invalid numbers that will not

be issued for another 10 years cannot be used in error)

  • To each of the base number’s eight digits a weight factor is assigned. From left to right

these are: 3, 2, 7, 6, 5, 4, 3, 2.

  • Where the base number is seven digits remember there is a leading zero.

  • Sum together the products of the weight factors and their associated digits.

  • Divide the sum by 11. If the remainder is 0 then the check digit is 0.

  • If the remainder is not 0 then subtract this number from 11, giving the check digit (0 - 9

are valid).

  • If the resulting check digit is 10, use a secondary set of weight factors and apply steps 2

and 3 to the same input base number. From left to right the factors for an eight digit base number are: 7, 4, 3, 2, 5, 2, 7, 6.

  • Remember there is a leading zero for a seven digit base number. If the new check digit

is again 10 then the IRD number is invalid (0 - 9 is valid).

  • Compare the calculated check digit with the check digit on the IRD number. If they

match then the IRD number is valid.

Returns:

  • (Boolean)


28
29
30
# File 'lib/weird.rb', line 28

def self.valid_ird? input
  is_integer(input) && valid_range(input) && check_digit_matches(input)
end

.version_stringObject



6
7
8
# File 'lib/weird.rb', line 6

def self.version_string
  "Weird version #{Weird::VERSION}"
end