Class: MiniMagick::CommandBuilder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool, *options) ⇒ CommandBuilder

Returns a new instance of CommandBuilder.



450
451
452
453
454
# File 'lib/mini_magick.rb', line 450

def initialize(tool, *options)
  @tool = tool
  @args = []
  options.each { |arg| push(arg) }
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



448
449
450
# File 'lib/mini_magick.rb', line 448

def args
  @args
end

Instance Method Details

#+(*options) ⇒ Object



492
493
494
495
496
497
498
499
# File 'lib/mini_magick.rb', line 492

def +(*options)
  push(@args.pop.gsub(/^-/, '+'))
  if options.any?
    options.each do |o|
      push escape_string(o)
    end
  end
end

#add_command(command, *options) ⇒ Object



501
502
503
504
505
506
507
508
# File 'lib/mini_magick.rb', line 501

def add_command(command, *options)
  push "-#{command}"
  if options.any?
    options.each do |o|
      push escape_string(o)
    end
  end
end

#add_creation_operator(command, *options) ⇒ Object



514
515
516
517
518
519
520
521
522
# File 'lib/mini_magick.rb', line 514

def add_creation_operator(command, *options)
  creation_command = command
  if options.any?
    options.each do |option|
      creation_command << ":#{option}"
    end
  end
  push creation_command
end

#commandObject



456
457
458
# File 'lib/mini_magick.rb', line 456

def command
  "#{MiniMagick.processor} #{@tool} #{@args.join(' ')}".strip
end

#escape_string(value) ⇒ Object



510
511
512
# File 'lib/mini_magick.rb', line 510

def escape_string(value)
  Shellwords.escape(value.to_s)
end

#format(*options) ⇒ Object

Raises:



481
482
483
# File 'lib/mini_magick.rb', line 481

def format(*options)
  raise Error, "You must call 'format' on the image object directly!"
end

#push(arg) ⇒ Object Also known as: <<



524
525
526
# File 'lib/mini_magick.rb', line 524

def push(arg)
  @args << arg.to_s.strip
end