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, String

Deprecated.

Use #checksum. Kept as a v7 bridge; removed in v8.

Returns the calculated checksum.

Parameters:

  • id (String)

    the identifier to calculate the checksum for

Returns:

  • (Integer, String)

    the calculated checksum

Raises:



97
98
99
100
# File 'lib/sec_id/concerns/checkable.rb', line 97

def check_digit(id)
  SecID::Deprecation.warn(old: 'check_digit', new: 'checksum')
  checksum(id)
end

#checksum(id) ⇒ Integer, String

Returns the calculated checksum.

Parameters:

  • id (String)

    the identifier to calculate checksum for

Returns:

  • (Integer, String)

    the calculated checksum

Raises:



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

def checksum(id)
  new(id).calculate_checksum
end

#restore(id_without_checksum) ⇒ String

Returns the full identifier string with correct checksum.

Parameters:

  • id_without_checksum (String)

    identifier without or with incorrect checksum

Returns:

  • (String)

    the full identifier with correct checksum

Raises:



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

def restore(id_without_checksum)
  new(id_without_checksum).restore
end

#restore!(id_without_checksum) ⇒ self

Restores (calculates) the checksum and returns the instance.

Parameters:

  • id_without_checksum (String)

    identifier without or with incorrect checksum

Returns:

  • (self)

    the restored instance with correct checksum

Raises:



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

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