Class: Postsvg::CLI

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

Overview

Command-line interface. Thor-based. Auto-detects conversion direction by file extension in batch.

Instance Method Summary collapse

Instance Method Details

#batch(input_dir, output_dir = nil) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/postsvg/cli.rb', line 66

def batch(input_dir, output_dir = nil)
  unless Dir.exist?(input_dir)
    say "Error: Input directory '#{input_dir}' not found", :red
    exit 1
  end

  Dir.mkdir(output_dir) if output_dir && !Dir.exist?(output_dir)

  files = Dir.glob(File.join(input_dir, "*.{ps,eps,svg}"), File::FNM_CASEFOLD)
  if files.empty?
    say "No PS, EPS, or SVG files found in #{input_dir}", :yellow
    return
  end

  say "Found #{files.size} file(s) to convert", :cyan
  files.each do |path|
    convert_in_batch(path, input_dir, output_dir)
  end
end

#convert(input_path, output_path = nil) ⇒ Object



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

def convert(input_path, output_path = nil)
  handle_input(input_path, output_path, method(:read_ps_to_svg), direction: "PS/EPS -> SVG")
end

#to_eps(input_path, output_path = nil) ⇒ Object



53
54
55
# File 'lib/postsvg/cli.rb', line 53

def to_eps(input_path, output_path = nil)
  handle_input(input_path, output_path, method(:read_svg_to_eps), direction: "SVG -> EPS")
end

#to_ps(input_path, output_path = nil) ⇒ Object



44
45
46
# File 'lib/postsvg/cli.rb', line 44

def to_ps(input_path, output_path = nil)
  handle_input(input_path, output_path, method(:read_svg_to_ps), direction: "SVG -> PS")
end

#to_svg(input_path, output_path = nil) ⇒ Object



30
31
32
# File 'lib/postsvg/cli.rb', line 30

def to_svg(input_path, output_path = nil)
  convert(input_path, output_path)
end

#versionObject



87
88
89
# File 'lib/postsvg/cli.rb', line 87

def version
  say "postsvg version #{Postsvg::VERSION}"
end