Class: Spelly

Inherits:
Object
  • Object
show all
Defined in:
lib/spelly.rb,
lib/spelly/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language) ⇒ Spelly

Returns a new instance of Spelly.



5
6
7
8
9
# File 'lib/spelly.rb', line 5

def initialize language
  path = File.expand_path("../lib/dict", File.dirname(__FILE__))
  # path = "#{Gem.loaded_specs['spelly'].full_gem_path}/lib/dict"
  @dict = Hunspell.new(path, language)
end

Instance Attribute Details

#dictObject

Returns the value of attribute dict.



3
4
5
# File 'lib/spelly.rb', line 3

def dict
  @dict
end

Instance Method Details

#spell_check(words) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/spelly.rb', line 11

def spell_check words
  results = []
  words.each do |word|
    unless @dict.check?(word)
      results << {word: word, suggest: @dict.suggest(word)}
    end
  end
  results
end