Class: Kotoshu::Cli::InteractiveReviewer

Inherits:
Object
  • Object
show all
Defined in:
lib/kotoshu/cli/interactive_reviewer.rb

Overview

Interactive review session for spell/grammar checking.

Provides a user-friendly terminal interface for reviewing errors with full navigation support (forward, backward, jump, skip, accept).

Examples:

Starting an interactive session

reviewer = InteractiveReviewer.new(document, analyzer)
reviewer.run  # Enters interactive loop

Batch mode (non-interactive)

reviewer = InteractiveReviewer.new(document, analyzer)
reporter = reviewer.run_batch  # Returns BatchReporter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, analyzer, formatter: nil) ⇒ InteractiveReviewer

Create a new interactive reviewer.

Parameters:

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 29

def initialize(document, analyzer, formatter: nil)
  raise ArgumentError, "Document required" unless document
  raise ArgumentError, "Analyzer required" unless analyzer

  @document = document
  @analyzer = analyzer

  # Analyze document for errors
  errors = @analyzer.analyze(@document)

  # Create navigation manager
  @navigation = NavigationManager.new(errors)

  # Create display formatter
  @formatter = formatter || DisplayFormatter.new

  @running = false
  @show_context = true
end

Instance Attribute Details

#analyzerObject (readonly)

Returns the value of attribute analyzer.



22
23
24
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 22

def analyzer
  @analyzer
end

#documentObject (readonly)

Returns the value of attribute document.



22
23
24
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 22

def document
  @document
end

#formatterObject (readonly)

Returns the value of attribute formatter.



22
23
24
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 22

def formatter
  @formatter
end

Returns the value of attribute navigation.



22
23
24
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 22

def navigation
  @navigation
end

Instance Method Details

#has_errors?Boolean

Check if session has errors.

Returns:

  • (Boolean)

    True if there are errors to review



96
97
98
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 96

def has_errors?
  @navigation.errors.any?
end

#runHash

Run the interactive review loop.

Returns:

  • (Hash)

    Session summary with statistics



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 52

def run
  @running = true

  # Show welcome message
  show_welcome

  # Show summary screen
  puts @formatter.summary_screen(@document, @navigation)

  # Main interactive loop
  while @running && @navigation.current
    show_current_error
    process_input(get_user_input)
  end

  # Show exit message
  show_exit_summary

  # Return session summary
  session_summary
end

#run_batchBatchReporter

Run in batch mode (non-interactive).

Returns:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 77

def run_batch
  # Analyze all errors without user interaction
  errors = @navigation.errors

  # Apply all high-confidence corrections automatically
  errors.each do |error|
    if error.high_confidence? && error.suggestions&.any?
      @navigation.accept_suggestion(error.recommended_suggestion)
    end
  end

  # Return batch reporter
  require_relative 'batch_reporter'
  BatchReporter.new(@document, @navigation, @formatter)
end

#statisticsHash

Get session statistics.

Returns:

  • (Hash)

    Statistics hash



103
104
105
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 103

def statistics
  @navigation.statistics
end