class MojoMagick::OptBuilder

Public Class Methods

new() click to toggle source
# File lib/mojo_magick/opt_builder.rb, line 4
def initialize
  @opts = []
end

Public Instance Methods

<<(arg) click to toggle source

Add command-line options with no processing

# File lib/mojo_magick/opt_builder.rb, line 9
def <<(arg)
  if arg.is_a?(Array)
    @opts += arg
  else
    @opts << arg
  end
  self
end
annotate(*args, geometry: 0) click to toggle source

annotate takes non-standard args

# File lib/mojo_magick/opt_builder.rb, line 30
def annotate(*args, geometry: 0)
  @opts << "-annotate"
  arguments = [args.join]
  arguments.unshift geometry.to_s
  @opts << arguments
end
blob(*args) click to toggle source
# File lib/mojo_magick/opt_builder.rb, line 43
def blob(*args)
  data = args[0]
  opts = args[1] || {}
  opts.each do |k, v|
    send(k.to_s, v.to_s)
  end
  tmpfile = MojoMagick.tempfile(data, opts)
  file tmpfile
end
file(*args) click to toggle source

Add files to command line, formatted if necessary

# File lib/mojo_magick/opt_builder.rb, line 19
def file(*args)
  @opts << args
  self
end
Also aliased as: files
files(*args)
Alias for: file
format(*args) click to toggle source

Create a temporary file for the given image and add to command line

# File lib/mojo_magick/opt_builder.rb, line 38
def format(*args)
  @opts << "-format"
  @opts << args
end
image_block() { |block| ... } click to toggle source
# File lib/mojo_magick/opt_builder.rb, line 53
def image_block(&block)
  @opts << '\('
  yield block
  @opts << '\)'
  self
end
label(*args) click to toggle source
# File lib/mojo_magick/opt_builder.rb, line 25
def label(*args)
  @opts << "label:#{quoted_arg(args.join)}"
end
method_missing(command, *args) click to toggle source

Generic commands. Arguments will be formatted if necessary rubocop:disable Style/MissingRespondToMissing

# File lib/mojo_magick/opt_builder.rb, line 62
def method_missing(command, *args)
  @opts << if command.to_s[-1, 1] == "!"
             "+#{command.to_s.chop}"
           else
             "-#{command}"
           end
  @opts << args
  self
end
to_a() click to toggle source

rubocop:enable Style/MissingRespondToMissing

# File lib/mojo_magick/opt_builder.rb, line 73
def to_a
  @opts.flatten
end

Protected Instance Methods

quoted_arg(arg) click to toggle source
# File lib/mojo_magick/opt_builder.rb, line 79
def quoted_arg(arg)
  return arg unless /[#'<>^|&();` ]/.match?(arg)

  ['"', arg.gsub('"', '\"').tr("'", "'"), '"'].join
end