Class: ImageProcessing::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/image_processing/pipeline.rb

Constant Summary collapse

DEFAULT_FORMAT =
"jpg"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Pipeline

Initializes the pipeline with all the processing options.



10
11
12
13
14
15
16
# File 'lib/image_processing/pipeline.rb', line 10

def initialize(options)
  fail Error, "source file is not provided" unless options[:source]

  options.each do |name, value|
    instance_variable_set(:"@#{name}", value)
  end
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



7
8
9
# File 'lib/image_processing/pipeline.rb', line 7

def destination
  @destination
end

#formatObject (readonly)

Returns the value of attribute format.



7
8
9
# File 'lib/image_processing/pipeline.rb', line 7

def format
  @format
end

#loaderObject (readonly)

Returns the value of attribute loader.



7
8
9
# File 'lib/image_processing/pipeline.rb', line 7

def loader
  @loader
end

#operationsObject (readonly)

Returns the value of attribute operations.



7
8
9
# File 'lib/image_processing/pipeline.rb', line 7

def operations
  @operations
end

#processorObject (readonly)

Returns the value of attribute processor.



7
8
9
# File 'lib/image_processing/pipeline.rb', line 7

def processor
  @processor
end

#saverObject (readonly)

Returns the value of attribute saver.



7
8
9
# File 'lib/image_processing/pipeline.rb', line 7

def saver
  @saver
end

Instance Method Details

#call(save: true) ⇒ Object

Determines the destination and calls the processor.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/image_processing/pipeline.rb', line 19

def call(save: true)
  if save == false
    call_processor
  elsif destination
    handle_destination do
      call_processor(destination: destination)
    end
  else
    create_tempfile do |tempfile|
      call_processor(destination: tempfile.path)
    end
  end
end

#destination_formatObject

Determines the appropriate destination image format.



39
40
41
42
43
44
45
# File 'lib/image_processing/pipeline.rb', line 39

def destination_format
  format   = determine_format(destination) if destination
  format ||= self.format
  format ||= determine_format(source_path) if source_path

  format || DEFAULT_FORMAT
end

#source_pathObject

Retrieves the source path on disk.



34
35
36
# File 'lib/image_processing/pipeline.rb', line 34

def source_path
  source if source.is_a?(String)
end