Class: Transloadit::Step

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, options = {})
  self.name    = name
  self.robot   = robot
  self.options = options
end

Instance Attribute Details

#nameString



13
14
15
# File 'lib/transloadit/step.rb', line 13

def name
  @name
end

#optionsHash



19
20
21
# File 'lib/transloadit/step.rb', line 19

def options
  @options
end

#robotString



16
17
18
# File 'lib/transloadit/step.rb', line 16

def robot
  @robot
end

Instance Method Details

#inspectString



64
65
66
# File 'lib/transloadit/step.rb', line 64

def inspect
  self.to_hash[self.name].inspect
end

#to_hashHash



71
72
73
# File 'lib/transloadit/step.rb', line 71

def to_hash
  { self.name => options.merge(:robot => self.robot) }
end

#to_jsonString



78
79
80
# File 'lib/transloadit/step.rb', line 78

def to_json
  MultiJson.dump(self.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)
  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