lib/pwm.rb in pwm-1.0.2 vs lib/pwm.rb in pwm-1.0.3
- old
+ new
@@ -1,13 +1,32 @@
require "pwm/version"
module Pwm
+
+ # Internal: The set of characters from which passwords will be assembled.
+ # This could be overridden if you don't like the default.
+ #
+ # Returns the set of characters as an Array.
def self.characters
- (('A'..'Z').to_a + ('a'..'z').to_a + ('2'..'9').to_a) - ['I', 'O', 'l']
+ (('A'..'Z').to_a + ('a'..'z').to_a +
+ ('2'..'9').to_a) - ['I', 'O', 'l']
end
- def self.password(length=16)
- (0..length-1).inject('') do |pw, n|
+ # Public: Generate a password.
+ #
+ # length - The length of the password.
+ #
+ # Examples
+ #
+ # Pwm.password
+ # # => 'SPdHeZnn9rut4AUz'
+ #
+ # Pwm.password(8)
+ # # => 'oUX4fmqr'
+ #
+ # Returns the generated password as a String.
+ def self.password(length = 16)
+ (0..length - 1).inject('') do |pw, n|
pw + characters[rand(characters.length)]
end
end
end