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.



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

def initialize
  @personal_dictionary_modified = false
  @stdin, @stdout, @stderr, @wait_thr =
    Open3.popen3("aspell -a")
  @stdout.gets # consume the banner
end

Instance Method Details

#add_to_personal_dictionary(word) ⇒ Object



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

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

#add_to_session_dictionary(word) ⇒ Object



31
32
33
# File 'lib/textbringer/commands/ispell.rb', line 31

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

#check_word(word) ⇒ Object



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

def check_word(word)
  send_command("^" + word)
  result = @stdout.gets
  @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



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

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

#personal_dictionary_modified?Boolean

Returns:

  • (Boolean)


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

def personal_dictionary_modified?
  @personal_dictionary_modified
end

#save_personal_dictionaryObject



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

def save_personal_dictionary
  send_command("#")
end

#send_command(line) ⇒ Object



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

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