class RackSpellChecker::RequestHandler
Handles incoming requests from the rack application TinyMCE issues two types of requests: checking for errors and suggesting replacements
Public Class Methods
check(content)
click to toggle source
checks the content for mispelled words
# File lib/rack_spellchecker/request_handler.rb, line 16 def self.check(content) bad_words = [] content.each do |word| unless spelling_utility.check(word) bad_words << word end end { "id" => nil, "error" => nil, "result" => bad_words.uniq } end
process(req)
click to toggle source
dispatches the request to a spelling check or alternative suggestion if TinyMCE supplied the method “getSuggestions” it will perform the spelling check
# File lib/rack_spellchecker/request_handler.rb, line 7 def self.process(req) if req["method"] == "getSuggestions" suggest_alternatives_for(req["params"][1], req["id"]) else check(req["params"][1]) end end
spelling_utility()
click to toggle source
# File lib/rack_spellchecker/request_handler.rb, line 40 def self.spelling_utility #nodoc Aspell.new("en") end
suggest_alternatives_for(word, position_id)
click to toggle source
suggests alternatives for a mispelled word
# File lib/rack_spellchecker/request_handler.rb, line 32 def self.suggest_alternatives_for(word, position_id) { "id" => position_id, "error" => nil, "result" => spelling_utility.suggest(word)[0..8] } end