Skip to content

Instantly share code, notes, and snippets.

@smileart
Created March 5, 2012 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smileart/1978294 to your computer and use it in GitHub Desktop.
Save smileart/1978294 to your computer and use it in GitHub Desktop.
Spell check plugin for earthquake.gem
# encoding: UTF-8
# Spell check plugin for earthquake.gem
#
# written by Smile @rT, https://github.com/smileart, smileart@mail.ru
#
# INSTALL:
#
# 1. Resolve dependencies of raspell.gem:
# https://github.com/evan/raspell/blob/master/README.rdoc
#
# 2. Install raspell.gem:
# OS X: gem install raspell -- --with-opt-dir=/opt/local
# Ubuntu: gem install raspell
#
# ===================== IF YOU ARE USE NON RUSSIAN DICT ====================
#
# 2.1 Install your native language dictionary:
# OS X: sudo port install aspell-dict-en
# Ubuntu: sudo apt-get install aspell-en
#
# 2.2 Set language code as @lang variable and alphabet pattern as @patern:
# @lang = 'en'
# @pattern = /[A-Za-z]+/i
#
# ================================== END ===================================
#
# 3. Put this file to ~/.earthquake/plugin/
#
# 4. PROFIT!!!111 > :update(<reply>) Текст с ашипкой ⏎
require 'raspell'
Earthquake.init do
# Set your native language code HERE!
# @lang = 'en'
@lang = 'ru'
# Set your alphabet pattern HERE!
# for eng:
# @pattern = /[A-Za-z]+/i
# or
# @pattern = /[\w]+/i
@pattern = /[А-Яа-я]+/i
input_filter do |text|
if text =~ /^:(update|reply)/
@had_mistake = false
speller = Aspell.new(@lang)
speller.suggestion_mode = Aspell::NORMAL
misspelled = text.gsub(@pattern) {|word|
if !speller.check(word)
@had_mistake = true
word.c(31)
else
word
end
}
puts "\nMisspelled text: ".c(31) + misspelled + "\n\n" if @had_mistake
text
else
text
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment