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 robot types and their parameters.
Instance Attribute Summary (collapse)
-
- (Hash) options
The robot's options.
-
- (String) robot
readonly
The robot to use.
Instance Method Summary (collapse)
-
- (Step) initialize(robot, options = {})
constructor
Creates a new Step with the given robot.
-
- (String) inspect
A human-readable version of the Step.
-
- (String) name
Automatically generates a unique, 32-character hex name for the step that uses this robot.
-
- (Hash) to_h
A Transloadit-compatible Hash of the Step's contents.
-
- (String) to_json
JSON-encoded String containing the Step's hash contents.
-
- (String, ...) use(input)
Specifies that this Step should process the provided input instead of the output of the Step before it.
Constructor Details
- (Step) initialize(robot, options = {})
Creates a new Step with the given robot.
25 26 27 28 |
# File 'lib/transloadit/step.rb', line 25 def initialize(robot, = {}) self.robot = robot self. = end |
Instance Attribute Details
- (Hash) options
The robot's options
17 18 19 |
# File 'lib/transloadit/step.rb', line 17 def @options end |
- (String) robot
The robot to use
14 15 16 |
# File 'lib/transloadit/step.rb', line 14 def robot @robot end |
Instance Method Details
- (String) inspect
A human-readable version of the Step
71 72 73 |
# File 'lib/transloadit/step.rb', line 71 def inspect self.to_h[self.name].inspect end |
- (String) name
Automatically generates a unique, 32-character hex name for the step that uses this robot.
36 37 38 39 40 |
# File 'lib/transloadit/step.rb', line 36 def name # rand() is "good enough" for this; we generate 128 random bits (same # length as a UUID for future compatibility) and convert it to hex @name ||= rand(2 ** 128).to_s(16).rjust(32, '0') end |
- (Hash) to_h
A Transloadit-compatible Hash of the Step's contents
78 79 80 |
# File 'lib/transloadit/step.rb', line 78 def to_h { self.name => .merge(:robot => self.robot) } end |
- (String) to_json
JSON-encoded String containing the Step's hash contents
85 86 87 |
# File 'lib/transloadit/step.rb', line 85 def to_json self.to_h.to_json end |
- (String, ...) use(input)
Specifies that this Step should process the provided input instead of the output of the Step before it.
58 59 60 61 62 63 64 65 66 |
# File 'lib/transloadit/step.rb', line 58 def use(input) self..delete(:use) and return if input.nil? self.[:use] = case input when Symbol then input.inspect when Array then input.map {|i| i.name } else [ input.name ] end end |