Class: Gramrb::SpellChecker
- Inherits:
-
Object
- Object
- Gramrb::SpellChecker
- Defined in:
- lib/gramrb/spell_checker.rb
Instance Method Summary collapse
- #check_words(content) ⇒ Object
-
#initialize(allowlisted) ⇒ SpellChecker
constructor
A new instance of SpellChecker.
Constructor Details
#initialize(allowlisted) ⇒ SpellChecker
Returns a new instance of SpellChecker.
5 6 7 8 9 10 11 |
# File 'lib/gramrb/spell_checker.rb', line 5 def initialize(allowlisted) pws_path = File.join(Dir.tmpdir, 'gramrb.pws') File.write(pws_path, "personal_ws-1.1 en 0\n#{allowlisted.join("\n")}") @string_cleaner = StringCleaner.new @speller_gb = FFI::Aspell::Speller.new('en_GB', personal: pws_path) @speller_us = FFI::Aspell::Speller.new('en_US', personal: pws_path) end |
Instance Method Details
#check_words(content) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/gramrb/spell_checker.rb', line 13 def check_words(content) content.each_with_object([]) do |item, results| bad_words(item[:words]).each do |error| suggestion = @speller_us.suggestions(error).first || @speller_gb.suggestions(error).first results << { item: item[:item], line: item[:line], error:, suggestion: } end end end |