Class: Uniword::Spellcheck::SpellcheckResult
- Inherits:
-
Object
- Object
- Uniword::Spellcheck::SpellcheckResult
- Defined in:
- lib/uniword/spellcheck/spellcheck_result.rb
Overview
Holds spell and grammar check results.
Responsibility: Collect and report spellcheck findings. Single Responsibility - only manages result storage and output.
Instance Attribute Summary collapse
-
#grammar_issues ⇒ Object
readonly
Returns the value of attribute grammar_issues.
-
#misspellings ⇒ Object
readonly
Returns the value of attribute misspellings.
Instance Method Summary collapse
-
#add_grammar_issue(message:, position:, context: nil) ⇒ void
Add a grammar issue.
-
#add_misspelling(word:, position:, suggestions: []) ⇒ void
Add a misspelling.
-
#clean? ⇒ Boolean
Whether no issues were found.
-
#initialize ⇒ SpellcheckResult
constructor
Initialize an empty result set.
-
#issue_count ⇒ Integer
Total number of issues found.
-
#to_json(*_args) ⇒ String
Serialize results to JSON.
Constructor Details
#initialize ⇒ SpellcheckResult
Initialize an empty result set.
22 23 24 25 |
# File 'lib/uniword/spellcheck/spellcheck_result.rb', line 22 def initialize @misspellings = [] @grammar_issues = [] end |
Instance Attribute Details
#grammar_issues ⇒ Object (readonly)
Returns the value of attribute grammar_issues.
19 20 21 |
# File 'lib/uniword/spellcheck/spellcheck_result.rb', line 19 def grammar_issues @grammar_issues end |
#misspellings ⇒ Object (readonly)
Returns the value of attribute misspellings.
19 20 21 |
# File 'lib/uniword/spellcheck/spellcheck_result.rb', line 19 def misspellings @misspellings end |
Instance Method Details
#add_grammar_issue(message:, position:, context: nil) ⇒ void
This method returns an undefined value.
Add a grammar issue.
47 48 49 50 51 52 53 |
# File 'lib/uniword/spellcheck/spellcheck_result.rb', line 47 def add_grammar_issue(message:, position:, context: nil) @grammar_issues << { message: , position: position, context: context, } end |
#add_misspelling(word:, position:, suggestions: []) ⇒ void
This method returns an undefined value.
Add a misspelling.
33 34 35 36 37 38 39 |
# File 'lib/uniword/spellcheck/spellcheck_result.rb', line 33 def add_misspelling(word:, position:, suggestions: []) @misspellings << { word: word, position: position, suggestions: suggestions, } end |
#clean? ⇒ Boolean
Whether no issues were found.
58 59 60 |
# File 'lib/uniword/spellcheck/spellcheck_result.rb', line 58 def clean? @misspellings.empty? && @grammar_issues.empty? end |
#issue_count ⇒ Integer
Total number of issues found.
65 66 67 |
# File 'lib/uniword/spellcheck/spellcheck_result.rb', line 65 def issue_count @misspellings.size + @grammar_issues.size end |
#to_json(*_args) ⇒ String
Serialize results to JSON.
72 73 74 75 76 77 78 79 |
# File 'lib/uniword/spellcheck/spellcheck_result.rb', line 72 def to_json(*_args) JSON.pretty_generate( misspellings: misspellings, grammar_issues: grammar_issues, issue_count: issue_count, clean: clean?, ) end |