Class: Zxcvbn::DictionaryRanker Private

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

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



13
14
15
16
17
# File 'lib/zxcvbn/dictionary_ranker.rb', line 13

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



23
24
25
26
27
28
29
# File 'lib/zxcvbn/dictionary_ranker.rb', line 23

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