class Transloadit::Step
Implements the concept of a step in the Transloadit
API. Each Step
has a robot
(e.g., '/image/resize' or '/video/thumbnail') and a hash of options
specific to the chosen robot.
See the Transloadit
documentation for futher information on robot types and their parameters.
Attributes
@return [String] the name to give the step
@return [Hash] the robot's options
@return [String] the robot to use
Public Class Methods
Creates a new Step
with the given robot
.
@param [String] name the explicit name to give the step @param [String] robot the robot to use @param [Hash] options the configuration options for the robot; see
{Transloadit#step} for possible values
# File lib/transloadit/step.rb, line 29 def initialize(name, robot, options = {}) self.name = name self.robot = robot self.options = options end
Public Instance Methods
@return [String] a human-readable version of the Step
# File lib/transloadit/step.rb, line 64 def inspect self.to_hash[self.name].inspect end
@return [Hash] a Transloadit-compatible Hash of the Step's contents
# File lib/transloadit/step.rb, line 71 def to_hash { self.name => options.merge(:robot => self.robot) } end
@return [String] JSON-encoded String containing the Step's hash contents
# File lib/transloadit/step.rb, line 78 def to_json MultiJson.dump(self.to_hash) end
Specifies that this Step
should process the provided input
instead of the output of the Step
before it.
@param [Step, Array<Step>, Symbol, nil] input The input
step to use. Follows the conventions outlined in the online {documentation}[http://transloadit.com/docs/building-assembly-instructions#special-parameters]. The symbol +:original+ specifies that the original file should be sent to the robot. A Step indicates that this Step's output should be used as the input to this one. Likewise, an array of Steps tells Transloadit to use pass each of their outputs to this Step. And lastly, an explicit nil clears the setting and restores it to its default input.
@return [String, Array<String>, nil> The value for the :use
parameter
that will actually be sent to the REST API.
# File lib/transloadit/step.rb, line 51 def use(input) self.options.delete(:use) and return if input.nil? self.options[:use] = case input when Symbol then input.inspect when Array then input.map {|i| i.name } else [ input.name ] end end