Class: Kotoshu::Cli::NavigationManager
- Inherits:
-
Object
- Object
- Kotoshu::Cli::NavigationManager
- Defined in:
- lib/kotoshu/cli/navigation_manager.rb
Overview
Manages navigation through errors in interactive review mode.
Tracks current position, user decisions, and provides filtering for efficient error review.
Instance Attribute Summary collapse
-
#current_index ⇒ Object
readonly
Returns the value of attribute current_index.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#modified ⇒ Object
readonly
Returns the value of attribute modified.
-
#skipped ⇒ Object
readonly
Returns the value of attribute skipped.
Instance Method Summary collapse
-
#accept_suggestion(suggestion) ⇒ Models::SemanticError?
Accept a suggestion for the current error.
-
#backward ⇒ Models::SemanticError?
Move to previous error.
-
#by_status ⇒ Array<Models::SemanticError>
Get all errors sorted by status (pending first).
-
#current ⇒ Models::SemanticError?
Get the current error.
-
#export_corrections ⇒ Array<Hash>
Export corrections as a list of changes.
-
#filter_by_confidence(min_confidence: 0.0) ⇒ Array<Models::SemanticError>
Filter errors by minimum confidence.
-
#filter_by_type(*types) ⇒ Array<Models::SemanticError>
Filter errors by type(s).
-
#first ⇒ Models::SemanticError?
Jump to first error.
-
#forward ⇒ Models::SemanticError?
Move to next error.
-
#history_summary ⇒ Array<Hash>
Get user decision history.
-
#initialize(errors) ⇒ NavigationManager
constructor
Create a new navigation manager.
-
#jump_to(index) ⇒ Models::SemanticError?
Jump to specific error by index.
-
#last ⇒ Models::SemanticError?
Jump to last error.
-
#list_all ⇒ Array<String>
List all errors with their status.
-
#next? ⇒ Boolean
Check if there’s a next error.
-
#pending ⇒ Array<Models::SemanticError>
Get only pending errors (not skipped or modified).
-
#previous? ⇒ Boolean
Check if there’s a previous error.
-
#reset ⇒ void
Reset navigation state (clear all decisions).
-
#skip_current ⇒ Models::SemanticError?
Skip the current error.
-
#statistics ⇒ Hash
Get statistics about the errors.
Constructor Details
#initialize(errors) ⇒ NavigationManager
Create a new navigation manager.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 20 def initialize(errors) raise ArgumentError, "Errors cannot be nil" if errors.nil? raise ArgumentError, "Errors must be an Array" unless errors.is_a?(Array) @errors = errors.sort # Errors are Comparable @current_index = 0 @history = [] @skipped = Set.new @modified = Set.new @filters = {} end |
Instance Attribute Details
#current_index ⇒ Object (readonly)
Returns the value of attribute current_index.
15 16 17 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 15 def current_index @current_index end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
15 16 17 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 15 def errors @errors end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
15 16 17 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 15 def history @history end |
#modified ⇒ Object (readonly)
Returns the value of attribute modified.
15 16 17 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 15 def modified @modified end |
#skipped ⇒ Object (readonly)
Returns the value of attribute skipped.
15 16 17 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 15 def skipped @skipped end |
Instance Method Details
#accept_suggestion(suggestion) ⇒ Models::SemanticError?
Accept a suggestion for the current error.
Records the decision and marks the error as modified.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 116 def accept_suggestion(suggestion) error = current return nil unless error record_decision( error_id: error.id, action: :accept, original: error.original, replacement: suggestion.word, confidence: error.confidence ) @modified.add(@current_index) forward end |
#backward ⇒ Models::SemanticError?
Move to previous error.
70 71 72 73 74 75 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 70 def backward return nil unless previous? @current_index -= 1 current end |
#by_status ⇒ Array<Models::SemanticError>
Get all errors sorted by status (pending first).
188 189 190 191 192 193 194 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 188 def by_status pending + @errors.each_with_index.select { |_, idx| @modified.include?(idx) }.map(&:last).reverse + @errors.each_with_index.select { |_, idx| @skipped.include?(idx) }.map(&:last).reverse end |
#current ⇒ Models::SemanticError?
Get the current error.
35 36 37 38 39 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 35 def current return nil if @current_index >= @errors.size @errors[@current_index] end |
#export_corrections ⇒ Array<Hash>
Export corrections as a list of changes.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 209 def export_corrections @modified.to_a.sort.map do |idx| error = @errors[idx] suggestion = error.recommended_suggestion { line: error.location.line, original: error.original, replacement: suggestion.word, error_type: error.error_type, confidence: error.confidence } end end |
#filter_by_confidence(min_confidence: 0.0) ⇒ Array<Models::SemanticError>
Filter errors by minimum confidence.
146 147 148 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 146 def filter_by_confidence(min_confidence: 0.0) @errors.select { |e| e.confidence >= min_confidence } end |
#filter_by_type(*types) ⇒ Array<Models::SemanticError>
Filter errors by type(s).
154 155 156 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 154 def filter_by_type(*types) @errors.select { |e| types.include?(e.error_type) } end |
#first ⇒ Models::SemanticError?
Jump to first error.
91 92 93 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 91 def first jump_to(0) end |
#forward ⇒ Models::SemanticError?
Move to next error.
60 61 62 63 64 65 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 60 def forward return nil unless next? @current_index += 1 current end |
#history_summary ⇒ Array<Hash>
Get user decision history.
227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 227 def history_summary @history.map.with_index.map do |decision, idx| { id: idx + 1, error_id: decision[:error_id], action: decision[:action], original: decision[:original], replacement: decision[:replacement], confidence: decision[:confidence], timestamp: decision[:timestamp] } end end |
#jump_to(index) ⇒ Models::SemanticError?
Jump to specific error by index.
81 82 83 84 85 86 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 81 def jump_to(index) return nil if index < 0 || index >= @errors.size @current_index = index current end |
#last ⇒ Models::SemanticError?
Jump to last error.
98 99 100 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 98 def last jump_to(@errors.size - 1) end |
#list_all ⇒ Array<String>
List all errors with their status.
135 136 137 138 139 140 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 135 def list_all @errors.each_with_index.map do |error, idx| status = status_for(idx) "#{idx + 1}. #{status} #{error.abbreviated}" end end |
#next? ⇒ Boolean
Check if there’s a next error.
44 45 46 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 44 def next? @current_index < @errors.size - 1 end |
#pending ⇒ Array<Models::SemanticError>
Get only pending errors (not skipped or modified).
161 162 163 164 165 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 161 def pending @errors.each_with_index.reject do |_, idx| @skipped.include?(idx) || @modified.include?(idx) end.map(&:last) end |
#previous? ⇒ Boolean
Check if there’s a previous error.
51 52 53 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 51 def previous? @current_index > 0 end |
#reset ⇒ void
This method returns an undefined value.
Reset navigation state (clear all decisions).
199 200 201 202 203 204 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 199 def reset @current_index = 0 @history.clear @skipped.clear @modified.clear end |
#skip_current ⇒ Models::SemanticError?
Skip the current error.
105 106 107 108 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 105 def skip_current @skipped.add(@current_index) forward end |
#statistics ⇒ Hash
Get statistics about the errors.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/kotoshu/cli/navigation_manager.rb', line 170 def statistics { total: @errors.size, skipped: @skipped.size, modified: @modified.size, pending: pending.size, by_type: @errors.group_by(&:error_type).transform_values(&:size), by_confidence: { high: @errors.count(&:high_confidence?), medium: @errors.count { |e| e.confidence > 0.5 && e.confidence <= 0.8 }, low: @errors.count { |e| e.confidence <= 0.5 } } } end |