class AlfonsoX::SpellChecker::Dictionary::DictionaryFinder
Finds the dictionary in this Gem
Constants
- PATH
Attributes
aff_file_path[R]
dic_file_path[R]
Public Class Methods
find_from_language(language, path)
click to toggle source
Find language dictionary in a path @return [Array<String, nil>] an array with two elements.
If they are both strings, it will be the paths of aff and dic files. Otherwise, if they are both nils, no dictionary could be found for the language.
# File lib/alfonsox/spellchecker/dictionary/hunspell.rb, line 66 def self.find_from_language(language, path) standard_language = language.split('_')[0] languages = [language, standard_language, "#{standard_language}_ANY}"] languages.each do |language_directory| next unless ::Dir.exist?("#{path}/#{language_directory}") languages.each do |language_file| file_common_path = "#{path}/#{language_directory}/#{language_file}" aff_file_path = "#{file_common_path}.aff" dic_file_path = "#{file_common_path}.dic" aff_file_exists = ::File.exist?(aff_file_path) dic_file_exists = ::File.exist?(dic_file_path) return aff_file_path, dic_file_path if aff_file_exists && dic_file_exists end end [nil, nil] end
new(language, path = nil)
click to toggle source
# File lib/alfonsox/spellchecker/dictionary/hunspell.rb, line 46 def initialize(language, path = nil) @language = language @path = path @aff_file_path = nil @dic_file_path = nil end
Public Instance Methods
find()
click to toggle source
# File lib/alfonsox/spellchecker/dictionary/hunspell.rb, line 53 def find paths = [@path, "#{AlfonsoX::DICTIONARIES_PATH}/hunspell"].compact paths.each do |path| @aff_file_path, @dic_file_path = DictionaryFinder.find_from_language(@language, path) return true if @aff_file_path && @dic_file_path end false end