Class: XKPassword::Words
- Inherits:
-
Object
- Object
- XKPassword::Words
- Defined in:
- lib/xkpassword/words.rb
Instance Attribute Summary collapse
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Instance Method Summary collapse
-
#initialize ⇒ Words
constructor
A new instance of Words.
- #lengths ⇒ Object
- #max_length ⇒ Object
- #min_length ⇒ Object
- #random(length) ⇒ Object
- #with_length(length) ⇒ Object
Constructor Details
#initialize ⇒ Words
Returns a new instance of Words.
6 7 8 9 |
# File 'lib/xkpassword/words.rb', line 6 def initialize @words = {} setup end |
Instance Attribute Details
#words ⇒ Object (readonly)
Returns the value of attribute words.
4 5 6 |
# File 'lib/xkpassword/words.rb', line 4 def words @words end |
Instance Method Details
#lengths ⇒ Object
21 22 23 |
# File 'lib/xkpassword/words.rb', line 21 def lengths words.keys.map{ |key| gsub(/l/, '').to_i } end |
#max_length ⇒ Object
29 30 31 |
# File 'lib/xkpassword/words.rb', line 29 def max_length lengths.max end |
#min_length ⇒ Object
25 26 27 |
# File 'lib/xkpassword/words.rb', line 25 def min_length lengths.min end |
#random(length) ⇒ Object
16 17 18 19 |
# File 'lib/xkpassword/words.rb', line 16 def random(length) fail ArgumentError, 'Length should be numeric' unless length.is_a? Numeric with_length(length).sample end |
#with_length(length) ⇒ Object
11 12 13 14 |
# File 'lib/xkpassword/words.rb', line 11 def with_length(length) fail ArgumentError 'Length should be a numeric' unless length.is_a? Numeric words[key(length)] end |