Class: HttpSpell::SpellChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/http_spell/spellchecker.rb

Instance Method Summary collapse

Constructor Details

#initialize(personal_dictionary_path = nil, verbose: false) ⇒ SpellChecker

Returns a new instance of SpellChecker.



5
6
7
8
# File 'lib/http_spell/spellchecker.rb', line 5

def initialize(personal_dictionary_path = nil, verbose: false)
  @personal_dictionary_arg = "-p #{personal_dictionary_path}" if personal_dictionary_path
  @verbose = verbose
end

Instance Method Details

#check(doc, lang) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/http_spell/spellchecker.rb', line 10

def check(doc, lang)
  commands = [
    'pandoc --from html --to plain',
    "hunspell -d #{translate(lang)} #{@personal_dictionary_arg} -i UTF-8 -l",
  ]

  Open3.pipeline_rw(*commands) do |stdin, stdout, _wait_thrs|
    stdin.puts(doc)
    stdin.close
    stdout.read.split.uniq
  end
end