Class: ImageVise::Pipeline
- Inherits:
-
Object
- Object
- ImageVise::Pipeline
show all
- Defined in:
- lib/image_vise/pipeline.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(operators = []) ⇒ Pipeline
Returns a new instance of Pipeline.
18
19
20
|
# File 'lib/image_vise/pipeline.rb', line 18
def initialize(operators = [])
@ops = operators.to_a
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, args = {}, &blk) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/image_vise/pipeline.rb', line 30
def method_missing(method_name, args = {}, &blk)
operator_builder = ImageVise.operator_from(method_name)
if args.empty? self << operator_builder.new
else
self << operator_builder.new(**args)
end
end
|
Class Method Details
.from_array_of_operator_params(array_of_operator_names_to_operator_params) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/image_vise/pipeline.rb', line 6
def self.from_array_of_operator_params(array_of_operator_names_to_operator_params)
operators = array_of_operator_names_to_operator_params.map do |(operator_name, operator_params)|
operator_class = operator_by_name(operator_name)
if operator_params && operator_params.any? && operator_class.method(:new).arity.nonzero?
operator_class.new(**operator_params)
else
operator_class.new
end
end
new(operators)
end
|
.operator_by_name(name) ⇒ Object
2
3
4
|
# File 'lib/image_vise/pipeline.rb', line 2
def self.operator_by_name(name)
operator = ImageVise.operator_from(name) or raise "Unknown operator #{name}"
end
|
Instance Method Details
#<<(image_operator) ⇒ Object
22
23
24
|
# File 'lib/image_vise/pipeline.rb', line 22
def <<(image_operator)
@ops << image_operator; self
end
|
#apply!(magick_image, image_metadata) ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'lib/image_vise/pipeline.rb', line 52
def apply!(magick_image, image_metadata)
@ops.each do |operator|
operator_short_classname = operator.class.to_s.split('::').pop
Measurometer.instrument('image_vise.op.%s' % operator_short_classname) do
apply_operator_passing_metadata(magick_image, operator, image_metadata)
end
end
end
|
61
62
63
64
65
66
67
|
# File 'lib/image_vise/pipeline.rb', line 61
def apply_operator_passing_metadata(magick_image, operator, image_metadata)
if operator.method(:apply!).arity == 1
operator.apply!(magick_image)
else
operator.apply!(magick_image, image_metadata)
end
end
|
#empty? ⇒ Boolean
26
27
28
|
# File 'lib/image_vise/pipeline.rb', line 26
def empty?
@ops.empty?
end
|
#respond_to_missing?(method_name, *a) ⇒ Boolean
40
41
42
|
# File 'lib/image_vise/pipeline.rb', line 40
def respond_to_missing?(method_name, *a)
ImageVise.defined_operators.include?(method_name.to_s)
end
|
#to_params ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/image_vise/pipeline.rb', line 44
def to_params
@ops.map do |operator|
operator_name = ImageVise.operator_name_for(operator)
operator_params = operator.respond_to?(:to_h) ? operator.to_h : {}
[operator_name, operator_params]
end
end
|