Class: Multibases::Base32::Table

Inherits:
IndexedOrdTable show all
Defined in:
lib/multibases/base32.rb

Instance Attribute Summary

Attributes inherited from OrdTable

#base, #encoding, #factor, #padder

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from IndexedOrdTable

#decoded_length, #decoded_zeroes_length, #encoded_length, #encoded_zeroes_length, #index, #ord_at, #pad_to_power?, #zero

Methods inherited from OrdTable

#alphabet, #eql?, #hash, #strict?, #tr_ords

Constructor Details

#initialize(ords, **opts) ⇒ Table

Returns a new instance of Table.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/multibases/base32.rb', line 32

def initialize(ords, **opts)
  ords = ords.uniq

  if ords.length < 32 || ords.length > 33
    raise ArgumentError,
          'Expected alphabet to contain 32 characters or 32 + 1 ' \
          "padding character. Actual: #{ords.length} characters"
  end

  padder = nil
  *ords, padder = ords if ords.length == 33

  super(ords, padder: padder, **opts)
end

Class Method Details

.from(alphabet, **opts) ⇒ Object



25
26
27
28
29
30
# File 'lib/multibases/base32.rb', line 25

def self.from(alphabet, **opts)
  alphabet = alphabet.bytes if alphabet.respond_to?(:bytes)
  alphabet.map!(&:ord)

  new(alphabet, **opts)
end