Class: Multibases::Base16::Table

Inherits:
OrdTable
  • Object
show all
Defined in:
lib/multibases/base16.rb

Instance Attribute Summary

Attributes inherited from OrdTable

#base, #encoding, #factor, #padder

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OrdTable

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

Constructor Details

#initialize(ords, **opts) ⇒ Table

Returns a new instance of Table.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/multibases/base16.rb', line 41

def initialize(ords, **opts)
  ords = ords.uniq
  if ords.length < 16 || ords.length > 17
    # Allow 17 for stale padding that does nothing
    raise ArgumentError,
          'Expected alphabet to contain 16 exactly. Actual: ' \
          "#{ords.length} characters."
  end

  super ords, **opts
end

Class Method Details

.from(alphabet, **opts) ⇒ Object



34
35
36
37
38
39
# File 'lib/multibases/base16.rb', line 34

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

  new(alphabet, **opts)
end