Class: HttpSpell::SpellChecker

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SpellChecker.



3
4
5
6
# File 'lib/httpspell/spellchecker.rb', line 3

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/httpspell/spellchecker.rb', line 8

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

  if @verbose
    warn "Piping the HTML document into the following chain of commands:"
    warn commands
  end

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