Class: Uniword::WatermarkCLI

Inherits:
Thor
  • Object
show all
Includes:
CLIHelpers
Defined in:
lib/uniword/cli/watermark_cli.rb

Overview

Watermark subcommand for Uniword CLI.

Manages text watermarks in documents.

Instance Method Summary collapse

Methods included from CLIHelpers

included

Instance Method Details

#add(path, text) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/uniword/cli/watermark_cli.rb', line 27

def add(path, text)
  doc = load_document(path)
  manager = Watermark::Manager.new(doc)

  manager.add(text,
              color: options[:color],
              font_size: options["font-size"],
              font: options[:font])

  doc.save(options[:output])
  say "Added watermark '#{text}' to #{options[:output]}", :green
rescue Uniword::Error => e
  handle_error(e)
rescue StandardError => e
  handle_error(e)
end

#list(path) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/uniword/cli/watermark_cli.rb', line 77

def list(path)
  doc = load_document(path)
  manager = Watermark::Manager.new(doc)

  watermarks = manager.list
  if watermarks.empty?
    say "No watermarks found.", :yellow
    return
  end

  say "Watermarks (#{watermarks.count}):", :green
  watermarks.each_with_index do |text, i|
    say "  #{i + 1}. #{text}"
  end
rescue Uniword::Error => e
  handle_error(e)
rescue StandardError => e
  handle_error(e)
end

#remove(path) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/uniword/cli/watermark_cli.rb', line 52

def remove(path)
  doc = load_document(path)
  manager = Watermark::Manager.new(doc)

  count = manager.remove
  doc.save(options[:output])

  if count.positive?
    say "Removed #{count} watermark(s) from #{options[:output]}", :green
  else
    say "No watermarks found.", :yellow
  end
rescue Uniword::Error => e
  handle_error(e)
rescue StandardError => e
  handle_error(e)
end