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.



389
390
391
392
393
# File 'lib/mini_magick.rb', line 389

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



399
400
401
402
403
404
405
406
407
408
409
# File 'lib/mini_magick.rb', line 399

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.



386
387
388
# File 'lib/mini_magick.rb', line 386

def args
  @args
end

#commandObject (readonly)

Returns the value of attribute command.



387
388
389
# File 'lib/mini_magick.rb', line 387

def command
  @command
end

Instance Method Details

#+(*options) ⇒ Object



411
412
413
414
415
416
417
418
# File 'lib/mini_magick.rb', line 411

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

#add(command, *options) ⇒ Object



420
421
422
423
424
425
426
427
# File 'lib/mini_magick.rb', line 420

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

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



429
430
431
# File 'lib/mini_magick.rb', line 429

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