Class: FunnyYubikeyGenerator
- Inherits:
-
Object
- Object
- FunnyYubikeyGenerator
- Includes:
- Singleton
- Defined in:
- lib/funny_yubikey_generator.rb
Class Method Summary collapse
- .filter_words(dictionary) ⇒ Object
- .from_dictionary(dictionary) ⇒ Object
- .generate(colorize: false) ⇒ Object
Instance Method Summary collapse
- #generate(colorize: false) ⇒ Object
-
#initialize(words: load_default_words) ⇒ FunnyYubikeyGenerator
constructor
A new instance of FunnyYubikeyGenerator.
Constructor Details
#initialize(words: load_default_words) ⇒ FunnyYubikeyGenerator
Returns a new instance of FunnyYubikeyGenerator.
30 31 32 |
# File 'lib/funny_yubikey_generator.rb', line 30 def initialize(words: load_default_words) @indexed_words = words.group_by(&:length) end |
Class Method Details
.filter_words(dictionary) ⇒ Object
21 22 23 |
# File 'lib/funny_yubikey_generator.rb', line 21 def filter_words(dictionary) dictionary.scan(WORD_REGEX) end |
.from_dictionary(dictionary) ⇒ Object
16 17 18 19 |
# File 'lib/funny_yubikey_generator.rb', line 16 def from_dictionary(dictionary) words = filter_words(dictionary) new(words: words) end |
.generate(colorize: false) ⇒ Object
25 26 27 |
# File 'lib/funny_yubikey_generator.rb', line 25 def generate(colorize: false) instance.generate(colorize: colorize) end |
Instance Method Details
#generate(colorize: false) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/funny_yubikey_generator.rb', line 34 def generate(colorize: false) words = random_partition(40, @indexed_words.keys).map do |s| @indexed_words[s].sample end if colorize words.map!.with_index { |w, i| w.colorize(COLORS[i % COLORS.length]) } end "/cccc#{words.join}" end |