Class: Zxcvbn::DictionaryRanker Private

Inherits:
Object
  • Object
show all
Defined in:
lib/zxcvbn/dictionary_ranker.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Converts raw word lists into frequency-ranked dictionaries for matcher use.

Class Method Summary collapse

Class Method Details

.rank_dictionaries(lists) ⇒ Hash{Symbol => Hash{String => Integer}}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Ranks multiple word lists, returning a hash of ranked dictionaries.

Parameters:

  • lists (Hash{Symbol => Array<String>})

    named word lists

Returns:

  • (Hash{Symbol => Hash{String => Integer}})

    lowercased word → rank mappings



11
12
13
14
15
# File 'lib/zxcvbn/dictionary_ranker.rb', line 11

def self.rank_dictionaries(lists)
  lists.transform_values do |words|
    rank_dictionary(words)
  end
end

.rank_dictionary(words) ⇒ Hash{String => Integer}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Ranks a single word list; rank starts at 1 (most common).

Parameters:

  • words (Array<String>)

    ordered words (most common first)

Returns:

  • (Hash{String => Integer})

    lowercased word → 1-based rank



21
22
23
24
25
# File 'lib/zxcvbn/dictionary_ranker.rb', line 21

def self.rank_dictionary(words)
  words
    .each_with_index
    .with_object({}) { |(word, i), dictionary| dictionary[word.downcase] = i + 1 }
end