module MicroToken

Constants

ALPHANUMERIC_CHARS
ALPHA_CHARS
LOWER_ALPHA_CHARS
NUMERIC_CHARS
SIMILAR_CHARS
UPPER_ALPHA_CHARS
VERSION
VISUALLY_DISTINCT_CHARS

Public Class Methods

generate(length = 8, format = :alphanumeric) click to toggle source
# File lib/micro_token.rb, line 15
def generate length = 8, format = :alphanumeric
  (1..length).collect { send("generate_#{format}_char") }.join
end

Private Class Methods

generate_alpha_char() click to toggle source
# File lib/micro_token.rb, line 41
def generate_alpha_char
  pick_from(ALPHA_CHARS)
end
generate_alphanumeric_char() click to toggle source
# File lib/micro_token.rb, line 33
def generate_alphanumeric_char
  pick_from(ALPHANUMERIC_CHARS)
end
generate_distinct_char() click to toggle source
# File lib/micro_token.rb, line 21
def generate_distinct_char
  pick_from(VISUALLY_DISTINCT_CHARS)
end
generate_lowercase_char() click to toggle source
# File lib/micro_token.rb, line 29
def generate_lowercase_char
  pick_from(LOWER_ALPHA_CHARS)
end
generate_numeric_char() click to toggle source
# File lib/micro_token.rb, line 37
def generate_numeric_char
  pick_from(NUMERIC_CHARS)
end
generate_uppercase_char() click to toggle source
# File lib/micro_token.rb, line 25
def generate_uppercase_char
  pick_from(UPPER_ALPHA_CHARS)
end
pick_from(ary) click to toggle source
# File lib/micro_token.rb, line 49
def pick_from ary
  ary[rand(ary.size)]
end
rand(n) click to toggle source
# File lib/micro_token.rb, line 45
def rand n
  SecureRandom.random_number(n)
end