Class: FFI::Extractor::MetadataProcessor

Inherits:
Proc
  • Object
show all
Defined in:
lib/ffi/extractor/metadata_processor.rb

Constant Summary collapse

PLUGIN_NAMES =

Mapping of plugin paths to names

Hash.new do |plugin_names,plugin|
  libname = File.basename(plugin,File.extname(plugin))

  plugin_names[plugin] = libname.sub('libextractor_','').to_sym
end

Class Method Summary collapse

Class Method Details

.new {|plugin_name, type, format, mime_type, data| ... } ⇒ Proc

Wraps a Metadata Processor callback.

Yields:

  • (plugin_name, type, format, mime_type, data)

    The given block will be passed the extracted metadata.

Yield Parameters:

  • plugin_name (Symbol)

    The name of the plugin.

  • type (Symbol)

    The type of metadata.

  • format (:unknown, :utf8, :binary, :c_string)

    The format of the metadata.

  • mime_type (String)

    The MIME-type of the data.

  • data (String, FFI::Pointer)

    The extracted metadata. If the type is :unknown, the original FFI::Pointer object will be yielded.

Returns:

  • (Proc)

    The wrapped callback.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ffi/extractor/metadata_processor.rb', line 59

def self.new(&block)
  super do |cls,plugin,type,format,mime_type,data,size|
    catch(:return) {
      value = case format
              when :c_string, :utf8 then data.get_string(0,size)
              when :binary          then data.get_bytes(0,size)
              else                       data
              end

      yield PLUGIN_NAMES[plugin], type, format, mime_type, value

      0
    }
  end
end