Class: ImageProcessing::Pipeline
- Inherits:
-
Object
- Object
- ImageProcessing::Pipeline
- Defined in:
- lib/image_processing/pipeline.rb
Constant Summary collapse
- DEFAULT_FORMAT =
"jpg"
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
-
#operations ⇒ Object
readonly
Returns the value of attribute operations.
-
#processor ⇒ Object
readonly
Returns the value of attribute processor.
-
#saver ⇒ Object
readonly
Returns the value of attribute saver.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #call(save: true) ⇒ Object
- #destination_format ⇒ Object
-
#initialize(options) ⇒ Pipeline
constructor
A new instance of Pipeline.
- #source_path ⇒ Object
Constructor Details
#initialize(options) ⇒ Pipeline
Returns a new instance of Pipeline.
9 10 11 12 13 14 |
# File 'lib/image_processing/pipeline.rb', line 9 def initialize() .each do |name, value| value = normalize_source(value, ) if name == :source instance_variable_set(:"@#{name}", value) end end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
7 8 9 |
# File 'lib/image_processing/pipeline.rb', line 7 def destination @destination end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
7 8 9 |
# File 'lib/image_processing/pipeline.rb', line 7 def format @format end |
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
7 8 9 |
# File 'lib/image_processing/pipeline.rb', line 7 def loader @loader end |
#operations ⇒ Object (readonly)
Returns the value of attribute operations.
7 8 9 |
# File 'lib/image_processing/pipeline.rb', line 7 def operations @operations end |
#processor ⇒ Object (readonly)
Returns the value of attribute processor.
7 8 9 |
# File 'lib/image_processing/pipeline.rb', line 7 def processor @processor end |
#saver ⇒ Object (readonly)
Returns the value of attribute saver.
7 8 9 |
# File 'lib/image_processing/pipeline.rb', line 7 def saver @saver end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
7 8 9 |
# File 'lib/image_processing/pipeline.rb', line 7 def source @source end |
Instance Method Details
#call(save: true) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/image_processing/pipeline.rb', line 16 def call(save: true) accumulator = processor.load_image(source, **loader) operations.each do |name, args, block| accumulator = processor.apply_operation(accumulator, name, *args, &block) end if save == false accumulator elsif destination handle_destination do processor.save_image(accumulator, destination, **saver) end else create_tempfile do |tempfile| processor.save_image(accumulator, tempfile.path, **saver) end end end |
#destination_format ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/image_processing/pipeline.rb', line 40 def destination_format format = File.extname(destination)[1..-1] if destination format ||= self.format format ||= File.extname(source_path)[1..-1] if source_path format || DEFAULT_FORMAT end |
#source_path ⇒ Object
36 37 38 |
# File 'lib/image_processing/pipeline.rb', line 36 def source_path source if source.is_a?(String) end |