Class: Vivlio::Starter::CLI::Metrics::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio/starter/cli/metrics/runner.rb

Overview

metrics コマンドの実行を制御する

Defined Under Namespace

Classes: ChapterAnalysis, PlaceholderChapter

Instance Method Summary collapse

Constructor Details

#initialize(targets, options = {}) ⇒ Runner

Returns a new instance of Runner.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vivlio/starter/cli/metrics/runner.rb', line 38

def initialize(targets, options = {})
  @targets = Array(targets)
  @options = options
  @config = ConfigLoader.new
  @warning_checker = WarningChecker.new(@config)
  @formatter = Formatter.new(@config)
  @chapter_parser = ChapterParser.new(@warning_checker)
  @catalog_loader = CatalogLoader.new
  @cache = Cache.new
  @parallel_runner = ParallelRunner.new
  @analysis_buffer = {}
  @analysis_mutex = Mutex.new
end

Instance Method Details

#callObject

メトリクス分析を実行する



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/vivlio/starter/cli/metrics/runner.rb', line 53

def call
  files = resolve_files
  return warn_no_targets if files.empty?

  # JSON/YAML 出力は一括処理
  return output_structured(:json, files) if options[:json]
  return output_structured(:yaml, files) if options[:yaml]

  puts '📚 章別の解析結果'
  puts ''

  placeholders = build_placeholder_chapters(files)
  max_chars = [placeholders.map(&:chars).max || 1, 1].max
  file_order = files.each_with_index.to_h
  pending = {}
  next_display_index = 0

  all_analyses = analyze_chapters_with_progress(files) do |analysis|
    index = file_order[analysis.chapter.path]
    next unless index

    pending[index] = { analysis:, visible: analysis_visible?(analysis) }

    while pending.key?(next_display_index)
      entry = pending.delete(next_display_index)
      output_chapter_line(entry[:analysis].chapter, max_chars) if entry[:visible]
      next_display_index += 1
    end
  end

  visible_analyses = all_analyses.select { analysis_visible?(it) }
  if visible_analyses.empty?
    puts '(対象章がありません)'
    return warn_no_targets
  end

  final_basic, final_vocab, final_readability = aggregate_summary_from_analyses(all_analyses)
  output_final_summary(final_basic, final_vocab, final_readability)

  0
end