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:



101
102
103
104
# File 'lib/sec_id/concerns/checkable.rb', line 101

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:



92
93
94
# File 'lib/sec_id/concerns/checkable.rb', line 92

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:



76
77
78
# File 'lib/sec_id/concerns/checkable.rb', line 76

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:



85
86
87
# File 'lib/sec_id/concerns/checkable.rb', line 85

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