Sha256: b287892e033c76edeb1b0165cbae19dd5df3de597b5a7e45415811651527047e

Contents?: true

Size: 563 Bytes

Versions: 2

Compression:

Stored size: 563 Bytes

Contents

# frozen_string_literal: true

module Base32
  class Alphabet
    CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'

    attr_reader :chars

    alias to_s chars

    def initialize(chars)
      self.chars = chars
    end

    def inspect
      "#<#{self.class}:#{chars.inspect}>"
    end

    def chars=(chars)
      unless chars_valid?(chars)
        raise ArgumentError, 'Chars must have 32 unique characters'
      end

      @chars = chars
    end

    def chars_valid?(chars)
      chars.bytes.to_a.size == 32 && chars.bytes.to_a.uniq.size == 32
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
base32.rb-0.4.2 lib/base32/alphabet.rb
base32.rb-0.4.1 lib/base32/alphabet.rb