Module: ImageProcessing::Vips::Chainable

Included in:
ImageProcessing::Vips, Pipeline
Defined in:
lib/image_processing/vips/chainable.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/image_processing/vips/chainable.rb', line 31

def method_missing(name, *args)
  if name.to_s.end_with?("!")
    send(name.to_s.chomp("!"), *args).call!
  else
    operation(name, *args)
  end
end

Instance Method Details

#branch(options) ⇒ Object



46
47
48
# File 'lib/image_processing/vips/chainable.rb', line 46

def branch(options)
  Pipeline.new(options)
end

#call(file = nil, save: true) ⇒ Object



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

def call(file = nil, save: true)
  options = default_options
  options = options.merge(source: file) if file

  branch(options).call!(save: save)
end

#convert(format) ⇒ Object



8
9
10
# File 'lib/image_processing/vips/chainable.rb', line 8

def convert(format)
  branch default_options.merge(format: format)
end

#custom(&block) ⇒ Object



27
28
29
# File 'lib/image_processing/vips/chainable.rb', line 27

def custom(&block)
  operation(:custom, block)
end

#default_optionsObject



50
51
52
53
54
55
56
57
58
# File 'lib/image_processing/vips/chainable.rb', line 50

def default_options
  @default_options ||= {
    source:     nil,
    loader:     {},
    saver:      {},
    format:     nil,
    operations: [],
  }
end

#loader(**options) ⇒ Object



12
13
14
15
# File 'lib/image_processing/vips/chainable.rb', line 12

def loader(**options)
  loader = default_options[:loader].merge(options)
  branch default_options.merge(loader: loader)
end

#operation(name, *args) ⇒ Object



22
23
24
25
# File 'lib/image_processing/vips/chainable.rb', line 22

def operation(name, *args)
  operations = default_options[:operations] + [[name, args]]
  branch default_options.merge(operations: operations)
end

#saver(**options) ⇒ Object



17
18
19
20
# File 'lib/image_processing/vips/chainable.rb', line 17

def saver(**options)
  saver = default_options[:saver].merge(options)
  branch default_options.merge(saver: saver)
end

#source(file) ⇒ Object



4
5
6
# File 'lib/image_processing/vips/chainable.rb', line 4

def source(file)
  branch default_options.merge(source: file)
end