Class: Textbringer::Commands::Ispell

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

Instance Method Summary collapse

Constructor Details

#initializeIspell



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

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



38
39
40
41
# File 'lib/textbringer/commands/ispell.rb', line 38

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

#add_to_session_dictionary(word) ⇒ Object



34
35
36
# File 'lib/textbringer/commands/ispell.rb', line 34

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

#check_word(word) ⇒ Object



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

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



56
57
58
59
60
# File 'lib/textbringer/commands/ispell.rb', line 56

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

#personal_dictionary_modified?Boolean



43
44
45
# File 'lib/textbringer/commands/ispell.rb', line 43

def personal_dictionary_modified?
  @personal_dictionary_modified
end

#save_personal_dictionaryObject



47
48
49
# File 'lib/textbringer/commands/ispell.rb', line 47

def save_personal_dictionary
  send_command("#")
end

#send_command(line) ⇒ Object



51
52
53
54
# File 'lib/textbringer/commands/ispell.rb', line 51

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