Class: FLV::Edit::Processor::Base

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/flvedit/processor/base.rb

Overview

Base is the base class for all Processors. Processors are used to process FLV files. A FLV file can be seen as an enumeration of chunks, the first one being a Header and the following ones a series of Tags with different types of bodies: Audio, Video or Event. A Processor acts as an IO operation on such enumerations. They therefore take an enumeration of chunks as input and their output is similarly an enumeration of chunks. They can thus be chained together at will.

For example:

FLV::File.open("x.flv") do |f|
  Debug.new(Cut.new(f, :cut => "1m-")).first(10)
end
# ==> reads the file, skips the first minute, prints and returns the first 10 chunks

Processors acts as Enumerable, but #each, in that context, is an enumeration of chunks for one single file. Some processors act as more than one such enumeration (Reader, Split) To go through all, call #each_source or #process_all

Direct Known Subclasses

CommandLine, Debug, Head, Join, MetaDataMaker, Print, Reader, Save, Update

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source = nil, options = {}) ⇒ Base

Create a new processor, using the given source and options hash. Valid options depend on the class of Processor.



28
29
30
31
# File 'lib/flvedit/processor/base.rb', line 28

def initialize(source=nil, options={})
  @options = options.reverse_merge(:out => STDOUT)
  @source = source
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



24
25
26
# File 'lib/flvedit/processor/base.rb', line 24

def options
  @options
end

Instance Method Details

#cloneObject



50
51
52
# File 'lib/flvedit/processor/base.rb', line 50

def clone
  self.class.new(source.try(:clone), options)
end

#each(&block) ⇒ Object

Calls the given block once for each chunck, passing that chunk as argument



40
41
42
43
# File 'lib/flvedit/processor/base.rb', line 40

def each(&block)
  raise "There is no source for #{self}" unless source
  source.each(&block)
end

#each_source(&block) ⇒ Object

Calls the given block once for each source



34
35
36
37
# File 'lib/flvedit/processor/base.rb', line 34

def each_source(&block)
  raise "There is no source for #{self}" unless source
  source.each_source(&block)
end

#process_allObject

Simple utility going through each chunk of each source



46
47
48
# File 'lib/flvedit/processor/base.rb', line 46

def process_all
  each_source{ each{} }
end