Class: Senha::Base::Generator
- Inherits:
-
Object
- Object
- Senha::Base::Generator
- Defined in:
- lib/senha/base/generator.rb
Overview
A class for handling the generation of a password based on options
Instance Attribute Summary collapse
-
#available_chars ⇒ Object
Returns the value of attribute available_chars.
Instance Method Summary collapse
-
#initialize(options) ⇒ Generator
constructor
Creates a new instance of the Generator class.
-
#password(length = 10) ⇒ String
Generates a password.
Constructor Details
#initialize(options) ⇒ Generator
Creates a new instance of the Generator class
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/senha/base/generator.rb', line 37 def initialize() @available_chars = Array.new @numbers = ('0'..'9').to_a @lower_case = ('a'..'z').to_a @upper_case = ('A'..'Z').to_a @punctuation = %w(. , ! :).to_a @symbols = %w(~ ! @ # $ % ^ & * ( ) _).to_a if [:all] @available_chars.concat @numbers @available_chars.concat @lower_case @available_chars.concat @upper_case @available_chars.concat @symbols @available_chars.concat @punctuation else if [:numbers] @available_chars.concat @numbers end if [:lowercase] @available_chars.concat @lower_case end if [:uppercase] @available_chars.concat @upper_case end if [:symbols] @available_chars.concat @symbols end if [:punct] @available_chars.concat @punctuation end end end |
Instance Attribute Details
#available_chars ⇒ Object
Returns the value of attribute available_chars.
32 33 34 |
# File 'lib/senha/base/generator.rb', line 32 def available_chars @available_chars end |
Instance Method Details
#password(length = 10) ⇒ String
Generates a password
78 79 80 81 82 |
# File 'lib/senha/base/generator.rb', line 78 def password(length = 10) 1.upto(length).collect do |a| @available_chars[rand(@available_chars.size)] end.join end |