Class: XKPassword::Words

Inherits:
Object
  • Object
show all
Defined in:
lib/xkpassword/words.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWords

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

#wordsObject (readonly)

Returns the value of attribute words.



4
5
6
# File 'lib/xkpassword/words.rb', line 4

def words
  @words
end

Instance Method Details

#lengthsObject



21
22
23
# File 'lib/xkpassword/words.rb', line 21

def lengths
  words.keys.map{ |key| gsub(/l/, '').to_i }
end

#max_lengthObject



29
30
31
# File 'lib/xkpassword/words.rb', line 29

def max_length
  lengths.max
end

#min_lengthObject



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