Module: Spellchecker::Dictionaries::TyposList

Defined in:
lib/spellchecker/dictionaries/typos_list.rb

Constant Summary collapse

MUTEX =
Mutex.new
PATH =
Dictionaries.path.join('typos.csv')

Class Method Summary collapse

Class Method Details

.allHash<String, String>

Returns:

  • (Hash<String, String>)


12
13
14
15
16
# File 'lib/spellchecker/dictionaries/typos_list.rb', line 12

def all
  @all || MUTEX.synchronize do
    @all ||= CSV.parse(PATH.read).to_h
  end
end

.include?(word) ⇒ Boolean

Parameters:

  • word (String)

Returns:

  • (Boolean)


20
21
22
# File 'lib/spellchecker/dictionaries/typos_list.rb', line 20

def include?(word)
  !match(word).nil?
end

.match(word) ⇒ String?

Parameters:

  • word (String)

Returns:

  • (String, nil)


26
27
28
# File 'lib/spellchecker/dictionaries/typos_list.rb', line 26

def match(word)
  all[Utils.replace_quote(word.to_s.downcase)]
end

.match_token(token) ⇒ String?

Parameters:

Returns:

  • (String, nil)


32
33
34
# File 'lib/spellchecker/dictionaries/typos_list.rb', line 32

def match_token(token)
  all[token.normalized]
end