Class: RandomPassword::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/random_password/base.rb

Constant Summary collapse

LETTERS =
[*'a'..'z', *'A'..'Z'].freeze
DIGITS =
[*'0'..'9'].freeze
SYMBOLS =
%w(! " # $ % & ' ( ) * + , - . / \\ : ; ? @ [ ] ^ _ ` { | } ~).freeze

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Base

Returns a new instance of Base.



9
10
11
# File 'lib/random_password/base.rb', line 9

def initialize(**options)
  update(options)
end

Instance Method Details

#generateObject



13
14
15
# File 'lib/random_password/base.rb', line 13

def generate
  password_letters.shuffle(random: Random.new).join[0, @length]
end

#update(**options) ⇒ Object



17
18
19
20
21
22
# File 'lib/random_password/base.rb', line 17

def update(**options)
  @length  = options[:length].to_i
  @digits  = options[:digits].to_i
  @symbols = options[:symbols].to_i
  self
end