Sha256: b3d7f44424f7985cbf537c075790c28a38533973c86ac20055ec1fcedbfb8c98

Contents?: true

Size: 638 Bytes

Versions: 1

Compression:

Stored size: 638 Bytes

Contents

module Stig
  module Generators
    module Character
      ASCII     = 0.upto(127).map(&:chr)
      PRINTABLE = 32.upto(126).map(&:chr)
      DIGITS    = 48.upto(57).map(&:chr)
      UPPERCASE = 65.upto(90).map(&:chr)
      LOWERCASE = 97.upto(122).map(&:chr)
      ALPHABET  = UPPERCASE + LOWERCASE

      # Public: Generates a random character.
      #
      # set - An Array of one character Strings.
      #
      # Returns a 1 character String.
      # Raises ArgumentError when `set` is empty.
      def self.random(set = ASCII)
        set = set.sample || raise(ArgumentError, "character set is empty")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stig-0.1.0 lib/stig/generators/character.rb