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

#checksum(id) ⇒ Integer, String

Returns the calculated checksum.

Parameters:

  • id (String) —

    the identifier to calculate checksum for

Returns:

  • (Integer, String) —

    the calculated checksum

Raises:



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

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:



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

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:



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

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