Class: Textbringer::Commands::Ispell

Inherits:
Object
  • Object
show all
Defined in:
lib/textbringer/commands/ispell.rb

Instance Method Summary collapse

Constructor Details

#initializeIspell

Returns a new instance of Ispell.



9
10
11
12
13
14
# File 'lib/textbringer/commands/ispell.rb', line 9

def initialize
  @personal_dictionary_modified = false
  @stdin, @stdout, @stderr, @wait_thr =
    Open3.popen3(CONFIG[:ispell_command])
  @stdout.gets # consume the banner
end

Instance Method Details

#add_to_personal_dictionary(word) ⇒ Object



40
41
42
43
# File 'lib/textbringer/commands/ispell.rb', line 40

def add_to_personal_dictionary(word)
  send_command("*" + word)
  @personal_dictionary_modified = true
end

#add_to_session_dictionary(word) ⇒ Object



36
37
38
# File 'lib/textbringer/commands/ispell.rb', line 36

def add_to_session_dictionary(word)
  send_command("@" + word)
end

#check_word(word) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/textbringer/commands/ispell.rb', line 16

def check_word(word)
  send_command("^" + word)
  result = @stdout.gets
  if result.nil? || result == "\n"
    # aspell can't handle word, which may contain multibyte characters
    return [word, nil]
  end
  @stdout.gets
  case result
  when /\A&\s+([^\s]+)\s+\d+\s+\d+:\s+(.*)/
    [$1, $2.split(/, /)]
  when /\A\*/, /\A\+/, /\A\-/, /\A\%/
    [word, []]
  when /\A#/
    [word, nil]
  else
    raise "unexpected output from aspell: #{result}"
  end
end

#closeObject



58
59
60
61
62
# File 'lib/textbringer/commands/ispell.rb', line 58

def close
  @stdin.close
  @stdout.close
  @stderr.close
end

#personal_dictionary_modified?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/textbringer/commands/ispell.rb', line 45

def personal_dictionary_modified?
  @personal_dictionary_modified
end

#save_personal_dictionaryObject



49
50
51
# File 'lib/textbringer/commands/ispell.rb', line 49

def save_personal_dictionary
  send_command("#")
end

#send_command(line) ⇒ Object



53
54
55
56
# File 'lib/textbringer/commands/ispell.rb', line 53

def send_command(line)
  @stdin.puts(line)
  @stdin.flush
end