Class: Naiso::CLI

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

Overview

CLI 인터페이스

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/naiso/cli.rb', line 8

def initialize
  @options = {
    threshold: 10.0,
    gap: 50,
    min_height: nil,
    max_height: nil,
    output: nil,
    check_text: false,
    json_output: nil,
    merge: false,
    merge_only: false
  }
end

Instance Method Details

#run(args = ARGV) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/naiso/cli.rb', line 22

def run(args = ARGV)
  parse_args(args)

  # 병합만 수행하는 경우
  if @options[:merge_only]
    ImageMerger.merge_sections(@options[:merge_only])
    return
  end

  config = SplitConfig.new(
    variance_threshold: @options[:threshold],
    min_gap_height: @options[:gap],
    min_section_height: @options[:min_height],
    max_section_height: @options[:max_height]
  )

  splitter = ImageSplitter.new(config)
  result = splitter.split(@options[:image], output_dir: @options[:output])

  # 텍스트 검출 옵션이 활성화된 경우
  if @options[:check_text] && result.output_files.any?
    detector = TextDetector.new

    # JSON 경로 결정 (지정하지 않으면 출력 디렉토리에 자동 생성)
    json_path = @options[:json_output]
    if json_path.nil? && @options[:check_text]
      output_dir = @options[:output] || File.join(File.dirname(@options[:image]), 'sections')
      base_name = File.basename(@options[:image], '.*')
      json_path = File.join(output_dir, "#{base_name}_text_analysis.json")
    end

    detector.analyze_images(result.output_files, json_path: json_path)
  end

  # 병합 옵션이 활성화된 경우
  if @options[:merge] && result.output_files.any?
    output_dir = @options[:output] || File.join(File.dirname(@options[:image]), 'sections')
    ImageMerger.merge_sections(output_dir)
  end
end