lib/ffi/hunspell/hunspell.rb in ffi-hunspell-0.2.0 vs lib/ffi/hunspell/hunspell.rb in ffi-hunspell-0.2.2
- old
+ new
@@ -1,6 +1,7 @@
require 'ffi'
+require 'env'
module FFI
module Hunspell
extend FFI::Library
@@ -37,15 +38,11 @@
# The name of the default language.
#
# @since 0.2.0
#
def Hunspell.lang
- @lang ||= if ENV['LANG']
- ENV['LANG'].split('.',2).first
- else
- DEFAULT_LANG
- end
+ @lang ||= (Env.lang[0] || DEFAULT_LANG)
end
#
# Sets the default language.
#
@@ -59,27 +56,39 @@
#
def Hunspell.lang=(new_lang)
@lang = new_lang.to_s
end
+ # The directory name used to store user installed dictionaries.
+ USER_DIR = '.hunspell_default'
+
+ # Known directories to search within for dictionaries.
+ KNOWN_DIRECTORIES = [
+ # User
+ Env.home.join(USER_DIR),
+ # Debian
+ '/usr/local/share/myspell/dicts',
+ '/usr/share/myspell/dicts',
+ # Fedora
+ '/usr/local/share/myspell',
+ '/usr/share/myspell',
+ # Mac Ports
+ '/opt/local/share/hunspell',
+ '/opt/share/hunspell'
+ ]
+
#
- # The directories to search for dictionary files.
+ # The dictionary directories to search for dictionary files.
#
- # @return [Array]
+ # @return [Array<String, Pathname>]
# The directory paths.
#
# @since 0.2.0
#
def Hunspell.directories
- @directories ||= [
- '/usr/local/share/myspell',
- '/usr/share/myspell'
- ]
- end
-
- # prepend the ~/.hunspell_default directory to DIRS
- if (home = (ENV['HOME'] || ENV['HOMEPATH']))
- directories.unshift(File.join(home,'.hunspell_default'))
+ @directories ||= KNOWN_DIRECTORIES.select do |path|
+ File.directory?(path)
+ end
end
#
# Opens a Hunspell dictionary.
#