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:

  • document (Object)

    Document to review (responds to #content)

  • analyzer (Analyzers::SemanticAnalyzer)

    Error analyzer

  • formatter (DisplayFormatter, nil) (defaults to: nil)

    Display formatter (default: new instance)

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 25

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.



18
19
20
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 18

def analyzer
  @analyzer
end

#documentObject (readonly)

Returns the value of attribute document.



18
19
20
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 18

def document
  @document
end

#formatterObject (readonly)

Returns the value of attribute formatter.



18
19
20
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 18

def formatter
  @formatter
end

Returns the value of attribute navigation.



18
19
20
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 18

def navigation
  @navigation
end

Instance Method Details

#has_errors?Boolean

Check if session has errors.

Returns:

  • (Boolean)

    True if there are errors to review



91
92
93
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 91

def has_errors?
  @navigation.errors.any?
end

#runHash

Run the interactive review loop.

Returns:

  • (Hash)

    Session summary with statistics



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 48

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:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 73

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
  BatchReporter.new(@document, @navigation, @formatter)
end

#statisticsHash

Get session statistics.

Returns:

  • (Hash)

    Statistics hash



98
99
100
# File 'lib/kotoshu/cli/interactive_reviewer.rb', line 98

def statistics
  @navigation.statistics
end