Class: Transloadit::Step
- Inherits:
-
Object
- Object
- Transloadit::Step
- Defined in:
- lib/transloadit/step.rb
Overview
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.
Instance Attribute Summary collapse
-
#name ⇒ String
The name to give the step.
-
#options ⇒ Hash
The robot’s options.
-
#robot ⇒ String
readonly
The robot to use.
Instance Method Summary collapse
-
#initialize(name, robot, options = {}) ⇒ Step
constructor
Creates a new Step with the given
robot
. -
#inspect ⇒ String
A human-readable version of the Step.
-
#to_hash ⇒ Hash
A Transloadit-compatible Hash of the Step’s contents.
-
#to_json ⇒ String
JSON-encoded String containing the Step’s hash contents.
-
#use(input) ⇒ String, ...
Specifies that this Step should process the provided
input
instead of the output of the Step before it.
Constructor Details
#initialize(name, robot, options = {}) ⇒ Step
Creates a new Step with the given robot
.
29 30 31 32 33 |
# File 'lib/transloadit/step.rb', line 29 def initialize(name, robot, = {}) self.name = name self.robot = robot self. = end |
Instance Attribute Details
#name ⇒ String
Returns the name to give the step.
13 14 15 |
# File 'lib/transloadit/step.rb', line 13 def name @name end |
#options ⇒ Hash
Returns the robot’s options.
19 20 21 |
# File 'lib/transloadit/step.rb', line 19 def @options end |
#robot ⇒ String
Returns the robot to use.
16 17 18 |
# File 'lib/transloadit/step.rb', line 16 def robot @robot end |
Instance Method Details
#inspect ⇒ String
Returns a human-readable version of the Step.
64 65 66 |
# File 'lib/transloadit/step.rb', line 64 def inspect to_hash[name].inspect end |
#to_hash ⇒ Hash
Returns a Transloadit-compatible Hash of the Step’s contents.
71 72 73 |
# File 'lib/transloadit/step.rb', line 71 def to_hash {name => .merge(robot: robot)} end |
#to_json ⇒ String
Returns JSON-encoded String containing the Step’s hash contents.
78 79 80 |
# File 'lib/transloadit/step.rb', line 78 def to_json MultiJson.dump(to_hash) end |
#use(input) ⇒ String, ...
Specifies that this Step should process the provided input
instead of the output of the Step before it.
51 52 53 54 55 56 57 58 59 |
# File 'lib/transloadit/step.rb', line 51 def use(input) .delete(:use) && return if input.nil? [:use] = case input when Symbol then input.inspect when Array then input.map { |i| i.name } else [input.name] end end |