lib/ffi/hunspell/hunspell.rb in ffi-hunspell-0.1.0 vs lib/ffi/hunspell/hunspell.rb in ffi-hunspell-0.2.0
- old
+ new
@@ -25,24 +25,78 @@
#
# attach_function :Hunspell_stem2, [:pointer, :pointer, :pointer, :int], :int
# attach_function :Hunspell_generate2, [:pointer, :pointer, :string, :pointer, :int], :int
#
+ # The language to default to, if no 'LANG' env variable was set.
+ DEFAULT_LANG = 'en_US'
+
#
+ # The default language.
+ #
+ # @return [String]
+ # 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
+ end
+
+ #
+ # Sets the default language.
+ #
+ # @param [String] name
+ # The new language name.
+ #
+ # @return [String]
+ # The name of the new default language.
+ #
+ # @since 0.2.0
+ #
+ def Hunspell.lang=(new_lang)
+ @lang = new_lang.to_s
+ end
+
+ #
+ # The directories to search for dictionary files.
+ #
+ # @return [Array]
+ # 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'))
+ end
+
+ #
# Opens a Hunspell dictionary.
#
- # @param [String] path
- # The path prefix shared by the `.aff` and `.dic` files.
+ # @param [Symbol, String] name
+ # The name of the dictionary to open.
#
# @yield [dict]
# The given block will be passed the Hunspell dictionary.
#
# @yieldparam [Dictionary] dict
# The opened dictionary.
#
# @return [nil]
#
- def Hunspell.dict(path,&block)
- Dictionary.open(path,&block)
+ def Hunspell.dict(name=Hunspell.lang,&block)
+ Dictionary.open(name,&block)
end
end
end