Class: MdSpell::SpellChecker
- Inherits:
-
Object
- Object
- MdSpell::SpellChecker
- Defined in:
- lib/mdspell/spell_checker.rb
Overview
A class for finding spelling errors in document.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
A Kramdown::Document object containing the parsed markdown document.
-
#filename ⇒ Object
readonly
Name of the file this object was created from.
Instance Method Summary collapse
-
#initialize(filename) ⇒ SpellChecker
constructor
Create a new instance from specified file.
-
#typos ⇒ Object
Returns found spelling errors.
Constructor Details
#initialize(filename) ⇒ SpellChecker
Create a new instance from specified file.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mdspell/spell_checker.rb', line 17 def initialize(filename) if filename == '-' @filename = 'stdin' text = STDIN.read else @filename = filename text = File.read(filename) end @document = Kramdown::Document.new(text, input: 'GFM') end |
Instance Attribute Details
#document ⇒ Object (readonly)
A Kramdown::Document object containing the parsed markdown document.
13 14 15 |
# File 'lib/mdspell/spell_checker.rb', line 13 def document @document end |
#filename ⇒ Object (readonly)
Name of the file this object was created from.
10 11 12 |
# File 'lib/mdspell/spell_checker.rb', line 10 def filename @filename end |
Instance Method Details
#typos ⇒ Object
Returns found spelling errors.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mdspell/spell_checker.rb', line 30 def typos results = [] FFI::Aspell::Speller.open(Configuration[:language]) do |speller| TextLine.scan(document).each do |line| line.words.each do |word| next if ignored? word unless speller.correct? word results << Typo.new(line, word, speller.suggestions(word)) end end end end results end |