Method: EncodedId::ReversibleId#initialize

Defined in:
lib/encoded_id/reversible_id.rb

#initialize(salt:, length: 8, split_at: 4, alphabet: ALPHABET, hex_digit_encoding_group_size: 4) ⇒ ReversibleId

Returns a new instance of ReversibleId.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/encoded_id/reversible_id.rb', line 13

def initialize(salt:, length: 8, split_at: 4, alphabet: ALPHABET, hex_digit_encoding_group_size: 4)
  unique_alphabet = alphabet.chars.uniq
  raise InvalidAlphabetError, "Alphabet must be at least 16 characters" if unique_alphabet.size < 16

  @human_friendly_alphabet = unique_alphabet.join
  @salt = salt
  @length = length
  @split_at = split_at
  # Number of hex digits to encode in each group, larger values will result in shorter hashes for longer inputs.
  # Vice versa for smaller values, ie a smaller value will result in smaller hashes for small inputs.
  @hex_digit_encoding_group_size = hex_digit_encoding_group_size
end