Class: FFmpeg::FilterGraph::FilterFactory

Inherits:
Object
  • Object
show all
Includes:
Utils::Strings
Defined in:
lib/ffmpeg/filter_graph/filter_factory.rb

Overview

This factory creates a new [Filter] subclass. The filters are all very silimar, so it’s easier to generate each class than to write them by hand.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Strings

#underscore

Constructor Details

#initialize(class_name, required, optional, editable, &options_string) ⇒ FilterFactory

Returns a new instance of FilterFactory.

Parameters:

  • class_name (#to_s)

    the name of the class to create

  • required (nil, Array<String>)

    an optional list of the filter options which must be passed to its constructor

  • optional (nil, Array<String>)

    an optional list of the filter options which are not required by the filter

  • editable (Bool)

    if this filter supports “Timeline editing”

  • options_string (Block)

    An optional callback to override the default method of constructing the string of options in the filter’s output.

See Also:



29
30
31
32
33
34
35
# File 'lib/ffmpeg/filter_graph/filter_factory.rb', line 29

def initialize(class_name, required, optional, editable, &options_string)
  self.class_name = class_name.to_s
  self.required = required || []
  self.optional = optional || []
  self.editable = editable
  self.options_string = options_string
end

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



7
8
9
# File 'lib/ffmpeg/filter_graph/filter_factory.rb', line 7

def class_name
  @class_name
end

#editableObject

Returns the value of attribute editable.



7
8
9
# File 'lib/ffmpeg/filter_graph/filter_factory.rb', line 7

def editable
  @editable
end

#optionalObject

Returns the value of attribute optional.



7
8
9
# File 'lib/ffmpeg/filter_graph/filter_factory.rb', line 7

def optional
  @optional
end

#options_stringObject

Returns the value of attribute options_string.



7
8
9
# File 'lib/ffmpeg/filter_graph/filter_factory.rb', line 7

def options_string
  @options_string
end

#requiredObject

Returns the value of attribute required.



7
8
9
# File 'lib/ffmpeg/filter_graph/filter_factory.rb', line 7

def required
  @required
end

Class Method Details

.create(name, opts) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/ffmpeg/filter_graph/filter_factory.rb', line 9

def self.create(name, opts)
  new(
    name,
    opts[:required],
    opts[:optional],
    opts[:editable],
    &opts[:options_string]
  )
end

Instance Method Details

#create_class_in(mod, helper_module: Helper) ⇒ Object

in. ex: if the filter class is named MyFilter, a method will be created in the form of Helper.my_filter(*args); MyFilter.new(*args) end

Parameters:

  • mod (Module)

    the module to create the new class in

  • helper_module (Module) (defaults to: Helper)

    an optional module to create a helper-method



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ffmpeg/filter_graph/filter_factory.rb', line 41

def create_class_in(mod, helper_module: Helper)
  # We need to make these local vars, to work in the Class.new block
  cn = class_name.to_s

  klass = create_class(cn, required, optional, editable, options_string)
  mod.const_set(cn, klass)

  if helper_module
    helper_name = underscore(cn)

    helper_module.module_exec do
      klass = mod.const_get(cn)
      define_method(helper_name) { |*args| klass.new(*args) }
    end
  end
end