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(command, *options) ⇒ CommandBuilder

Returns a new instance of CommandBuilder.



424
425
426
427
428
# File 'lib/mini_magick.rb', line 424

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *options) ⇒ Object



434
435
436
437
438
439
440
441
442
443
444
# File 'lib/mini_magick.rb', line 434

def method_missing(symbol, *options)
  guessed_command_name = symbol.to_s.gsub('_','-')
  if guessed_command_name == "format"
    raise Error, "You must call 'format' on the image object directly!"
  elsif MOGRIFY_COMMANDS.include?(guessed_command_name)
    add(guessed_command_name, *options)
    self
  else
    super(symbol, *args)
  end
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



421
422
423
# File 'lib/mini_magick.rb', line 421

def args
  @args
end

#commandObject (readonly)

Returns the value of attribute command.



422
423
424
# File 'lib/mini_magick.rb', line 422

def command
  @command
end

Instance Method Details

#+(*options) ⇒ Object



446
447
448
449
450
451
452
453
# File 'lib/mini_magick.rb', line 446

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

#add(command, *options) ⇒ Object



455
456
457
458
459
460
461
462
# File 'lib/mini_magick.rb', line 455

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

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



464
465
466
# File 'lib/mini_magick.rb', line 464

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