Sha256: 4fdbb602f735a2ebfe9cf6c402001123d258642d24168705075582ccd39f8f39

Contents?: true

Size: 965 Bytes

Versions: 21

Compression:

Stored size: 965 Bytes

Contents

module Scooter
  module Utilities
    module StringUtilities

      class RandomString
        def self.generate(length = 32)
          characters = [('0'..'9'), ('a'..'z'), ('A'..'Z')]
          characters = characters.map{ |i| i.to_a }.flatten
          (0...length).map{ characters[rand(characters.length)] }.join
        end
      end

      # Create a string of two-byte Cyrillic characters.
      class RandomTwoByteUnicodeString
        def self.generate(length = 32)
          characters  = (0x0400..0x04FF).to_a.map {|e| e.chr(Encoding::UTF_8) }
          (0...length).map{ characters[rand(characters.length)] }.join
        end
      end

      # Create some single-byte characters outside the ASCII 7-bit range.
      class RandomHighbitString
        def self.generate(length = 32)
          characters = (0x80..0xFF).to_a.map {|e| e.chr }
          (0...length).map{ characters[rand(characters.length)] }.join
        end
      end

    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
scooter-4.5.4 lib/scooter/utilities/string_utilities.rb
scooter-4.5.3 lib/scooter/utilities/string_utilities.rb
scooter-4.5.2 lib/scooter/utilities/string_utilities.rb
scooter-4.5.1 lib/scooter/utilities/string_utilities.rb
scooter-4.5.0 lib/scooter/utilities/string_utilities.rb
scooter-4.4.0 lib/scooter/utilities/string_utilities.rb
scooter-4.3.2 lib/scooter/utilities/string_utilities.rb
scooter-4.3.1 lib/scooter/utilities/string_utilities.rb
scooter-4.3.0 lib/scooter/utilities/string_utilities.rb
scooter-4.2.9 lib/scooter/utilities/string_utilities.rb
scooter-4.2.8 lib/scooter/utilities/string_utilities.rb
scooter-4.2.7 lib/scooter/utilities/string_utilities.rb
scooter-4.2.6 lib/scooter/utilities/string_utilities.rb
scooter-4.2.5 lib/scooter/utilities/string_utilities.rb
scooter-4.2.4 lib/scooter/utilities/string_utilities.rb
scooter-4.2.3 lib/scooter/utilities/string_utilities.rb
scooter-4.2.2 lib/scooter/utilities/string_utilities.rb
scooter-4.2.1 lib/scooter/utilities/string_utilities.rb
scooter-4.2.0 lib/scooter/utilities/string_utilities.rb
scooter-3.2.19 lib/scooter/utilities/string_utilities.rb