Class: Zxcvbn::Data Private
- Inherits:
-
Object
- Object
- Zxcvbn::Data
- Defined in:
- lib/zxcvbn/data.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.
Holds all loaded frequency lists, adjacency graphs, tries, and graph stats used by the matchers and scorer.
Constant Summary collapse
- RESERVED_NAMES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Built-in dictionary names and the reserved per-call key. These names cannot be passed to TesterBuilder#add_word_list.
%w[ english_wikipedia female_names male_names passwords surnames us_tv_and_film user_inputs ].freeze
Instance Attribute Summary collapse
-
#adjacency_graphs ⇒ Hash{String => Hash}
readonly
private
keyboard adjacency data.
-
#dictionaries ⇒ #ranked, #tries
readonly
private
consistent snapshot of ranked dictionaries and their tries; use this for concurrent reads to guarantee the pair is always in sync.
-
#graph_stats ⇒ Hash{String => Hash}
readonly
private
precomputed average degree and key count.
Instance Method Summary collapse
-
#add_word_list(name, list) ⇒ void
private
Adds a custom word list and builds a trie for it.
-
#dictionary_tries ⇒ Hash{String => Trie}
private
Prefix tries per dictionary.
-
#initialize ⇒ Data
constructor
private
Loads all built-in frequency lists and adjacency graphs from disk.
- #inspect ⇒ Object private
-
#ranked_dictionaries ⇒ Hash{String => Hash{String => Integer}}
private
Word → rank maps.
Constructor Details
#initialize ⇒ Data
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.
Loads all built-in frequency lists and adjacency graphs from disk.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/zxcvbn/data.rb', line 34 def initialize ranked = DictionaryRanker.rank_dictionaries( 'english_wikipedia' => read_word_list('english_wikipedia.txt'), 'female_names' => read_word_list('female_names.txt'), 'male_names' => read_word_list('male_names.txt'), 'passwords' => read_word_list('passwords.txt'), 'surnames' => read_word_list('surnames.txt'), 'us_tv_and_film' => read_word_list('us_tv_and_film.txt') ).tap { |r| r.each_value(&:freeze) }.freeze tries = build_tries(ranked).tap { |t| t.each_value(&:freeze) }.freeze @dictionaries = Dictionaries.new(ranked:, tries:) @adjacency_graphs = JSON.parse(DATA_PATH.join('adjacency_graphs.json').read) .tap { |gs| gs.each_value { |g| g.each_value { |a| a.each(&:freeze).freeze }.freeze } } .freeze @graph_stats = compute_graph_stats.each_value(&:freeze).freeze end |
Instance Attribute Details
#adjacency_graphs ⇒ Hash{String => Hash} (readonly)
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.
keyboard adjacency data
17 18 19 |
# File 'lib/zxcvbn/data.rb', line 17 def adjacency_graphs @adjacency_graphs end |
#dictionaries ⇒ #ranked, #tries (readonly)
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.
consistent snapshot of ranked dictionaries and their tries; use this for concurrent reads to guarantee the pair is always in sync
17 18 19 |
# File 'lib/zxcvbn/data.rb', line 17 def dictionaries @dictionaries end |
#graph_stats ⇒ Hash{String => Hash} (readonly)
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.
precomputed average degree and key count
17 18 19 |
# File 'lib/zxcvbn/data.rb', line 17 def graph_stats @graph_stats end |
Instance Method Details
#add_word_list(name, list) ⇒ void
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.
This method returns an undefined value.
Adds a custom word list and builds a trie for it.
67 68 69 70 71 72 73 74 |
# File 'lib/zxcvbn/data.rb', line 67 def add_word_list(name, list) ranked_dict = DictionaryRanker.rank_dictionary(list.select { |w| w.is_a?(String) }).freeze trie = Trie.from_ranked(ranked_dict).freeze @dictionaries = @dictionaries.with( ranked: @dictionaries.ranked.merge(name => ranked_dict).freeze, tries: @dictionaries.tries.merge(name => trie).freeze ) end |
#dictionary_tries ⇒ Hash{String => Trie}
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.
Returns prefix tries per dictionary.
60 |
# File 'lib/zxcvbn/data.rb', line 60 def dictionary_tries = @dictionaries.tries |
#inspect ⇒ Object
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.
54 |
# File 'lib/zxcvbn/data.rb', line 54 def inspect = "#<#{self.class}:0x#{__id__.to_s(16)}>" |
#ranked_dictionaries ⇒ Hash{String => 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.
Returns word → rank maps.
57 |
# File 'lib/zxcvbn/data.rb', line 57 def ranked_dictionaries = @dictionaries.ranked |