Class: Uniword::Spellcheck::SpellChecker
- Inherits:
-
Object
- Object
- Uniword::Spellcheck::SpellChecker
- Defined in:
- lib/uniword/spellcheck/spell_checker.rb
Overview
Main orchestrator for spell and grammar checking.
Responsibility: Extract text from a document, delegate to HunspellAdapter for spell checking and GrammarChecker for grammar issues, then aggregate results into a SpellcheckResult.
Instance Attribute Summary collapse
-
#grammar_checker ⇒ Object
readonly
Returns the value of attribute grammar_checker.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#spell_adapter ⇒ Object
readonly
Returns the value of attribute spell_adapter.
Instance Method Summary collapse
-
#check(document) ⇒ SpellcheckResult
Run spell and grammar checks on a document.
-
#initialize(language: "en_US", dictionary: nil, spell_adapter: nil) ⇒ SpellChecker
constructor
Initialize the spell checker.
Constructor Details
#initialize(language: "en_US", dictionary: nil, spell_adapter: nil) ⇒ SpellChecker
Initialize the spell checker.
26 27 28 29 30 31 32 33 |
# File 'lib/uniword/spellcheck/spell_checker.rb', line 26 def initialize(language: "en_US", dictionary: nil, spell_adapter: nil) @language = language @dictionary = dictionary @spell_adapter = spell_adapter || HunspellAdapter.new(language: language) @grammar_checker = GrammarChecker.new end |
Instance Attribute Details
#grammar_checker ⇒ Object (readonly)
Returns the value of attribute grammar_checker.
17 18 19 |
# File 'lib/uniword/spellcheck/spell_checker.rb', line 17 def grammar_checker @grammar_checker end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
17 18 19 |
# File 'lib/uniword/spellcheck/spell_checker.rb', line 17 def language @language end |
#spell_adapter ⇒ Object (readonly)
Returns the value of attribute spell_adapter.
17 18 19 |
# File 'lib/uniword/spellcheck/spell_checker.rb', line 17 def spell_adapter @spell_adapter end |
Instance Method Details
#check(document) ⇒ SpellcheckResult
Run spell and grammar checks on a document.
39 40 41 42 43 44 45 46 47 |
# File 'lib/uniword/spellcheck/spell_checker.rb', line 39 def check(document) text = extract_text(document) result = SpellcheckResult.new check_spelling(text, result) check_grammar(text, result) result end |