module Diceudiceu::ClassMethods

Public Instance Methods

cli_exe() click to toggle source
# File diceu, line 48
def cli_exe
  puts mk_password
end
mk_password() click to toggle source
# File diceu, line 61
def mk_password
  inject_numbers = -> (str) do
    return str unless parsed_args.leet
    chance = 0.3
    str.split('')
      .map do |letter|
        next letter unless letter.downcase[/[aeio]/]
        next letter unless rand < chance
        {
          'a' => 4,
          'e' => 3,
          'i' => 1,
          'o' => 0,
        }[letter.downcase].to_s.green
      end
      .join
      # .then {|word| rand < chance ? word+rand(1..99).to_s : word}
  end

  inject_specials = -> (str) do
    return str unless parsed_args.symbols
    symbols = %{!@#$%^&*()_+<>?:;"'~`}
    chance = 0.3
    return str if rand > chance

    str + symbols.split('').secure_sample.blue
  end

  (0...parsed_args.size)
    .map{ DEFAULT_WORDLIST.secure_sample }
    .map(&:capitalize)
    .map(&inject_numbers)
    .map(&inject_specials)
    .tap{ |words|
      next unless parsed_args.numbers

      3.times {words << rand(0..9).to_s.yellow}
    }
    .shuffle
    .map{|word| word.split('')}
    .flatten
    .map{|letter| letter[/[A-Z]/] ? letter.bold : letter}
    .join
end
parsed_args() click to toggle source
# File diceu, line 52
def parsed_args
  @args ||= OpenStruct.new(DEFAULT_SETTINGS.merge(
    size: ARGV.find{|arg| arg[/^\d+$/]}.then{|num| num.nil? ? nil : num.to_i},
    symbols: ARGV.find{|arg| arg[/^sym/]},
    numbers: ARGV.find{|arg| arg[/^num/]},
    leet: ARGV.find{ |arg| arg[/^leet/] }
  ) {|k,o,n| n || o} )
end