Module: SecID::Checkable::ClassMethods

Defined in:
lib/sec_id/concerns/checkable.rb

Overview

Class methods added when Checkable is included.

Instance Method Summary collapse

Instance Method Details

#check_digit(id) ⇒ Integer

Returns the calculated check digit.

Parameters:

  • id (String)

    the identifier to calculate check digit for

Returns:

  • (Integer)

    the calculated check digit

Raises:



88
89
90
# File 'lib/sec_id/concerns/checkable.rb', line 88

def check_digit(id)
  new(id).calculate_check_digit
end

#restore(id_without_check_digit) ⇒ String

Returns the full identifier string with correct check digit.

Parameters:

  • id_without_check_digit (String)

    identifier without or with incorrect check digit

Returns:

  • (String)

    the full identifier with correct check digit

Raises:



72
73
74
# File 'lib/sec_id/concerns/checkable.rb', line 72

def restore(id_without_check_digit)
  new(id_without_check_digit).restore
end

#restore!(id_without_check_digit) ⇒ self

Restores (calculates) the check digit and returns the instance.

Parameters:

  • id_without_check_digit (String)

    identifier without or with incorrect check digit

Returns:

  • (self)

    the restored instance with correct check digit

Raises:



81
82
83
# File 'lib/sec_id/concerns/checkable.rb', line 81

def restore!(id_without_check_digit)
  new(id_without_check_digit).restore!
end