Class: ImageProcessing::Processor
- Inherits:
-
Object
- Object
- ImageProcessing::Processor
- Defined in:
- lib/image_processing/processor.rb
Overview
Abstract class inherited by individual processors.
Direct Known Subclasses
Class Method Summary collapse
-
.accumulator(name, klass) ⇒ Object
Use for processor subclasses to specify the name and the class of their accumulator object (e.g. MiniMagic::Tool or Vips::Image).
-
.apply_operation(accumulator, name, *args, &block) ⇒ Object
Calls the operation to perform the processing.
Instance Method Summary collapse
-
#custom(&block) ⇒ Object
Calls the given block with the accumulator object.
-
#initialize(accumulator = nil) ⇒ Processor
constructor
A new instance of Processor.
Constructor Details
#initialize(accumulator = nil) ⇒ Processor
Returns a new instance of Processor.
25 26 27 |
# File 'lib/image_processing/processor.rb', line 25 def initialize(accumulator = nil) @accumulator = accumulator end |
Class Method Details
.accumulator(name, klass) ⇒ Object
Use for processor subclasses to specify the name and the class of their accumulator object (e.g. MiniMagic::Tool or Vips::Image).
6 7 8 9 10 |
# File 'lib/image_processing/processor.rb', line 6 def self.accumulator(name, klass) define_method(name) { @accumulator } protected(name) const_set(:ACCUMULATOR_CLASS, klass) end |
.apply_operation(accumulator, name, *args, &block) ⇒ Object
Calls the operation to perform the processing. If the operation is defined on the processor (macro), calls it. Otherwise calls the operation directly on the accumulator object. This provides a common umbrella above defined macros and direct operations.
16 17 18 19 20 21 22 23 |
# File 'lib/image_processing/processor.rb', line 16 def self.apply_operation(accumulator, name, *args, &block) if (instance_methods - Object.instance_methods).include?(name) instance = new(accumulator) instance.public_send(name, *args, &block) else accumulator.send(name, *args, &block) end end |
Instance Method Details
#custom(&block) ⇒ Object
Calls the given block with the accumulator object. Useful for when you want to access the accumulator object directly.
31 32 33 |
# File 'lib/image_processing/processor.rb', line 31 def custom(&block) (block && block.call(@accumulator)) || @accumulator end |