lib/metadata/extract.rb
# Extracts text from a file by guessing mimetype and calling matching
# extractor methods (which mostly call external programs to do their bidding.)
#
# The extracted text is converted to UTF-8.
#
Extracts text from a file by guessing mimetype and calling matching
extractor methods (which mostly call external programs to do their bidding.)

The extracted text is converted to UTF-8.
Extracts text from a file by guessing mimetype and calling matching extractor methods ( which mostly call external programs to do their bidding . ) The extracted text is converted to UTF - 8 .
def extract_text(filename, mimetype=MimeInfo.get(filename.to_s), charset=nil, layout=false)
    filename = filename.to_s
    mimetype = Mimetype[mimetype] unless mimetype.is_a?( Mimetype )
    mts = mimetype.ancestors
    mt = mts.shift
    new_methods = public_methods(false)
    STDERR.puts " Text extraction" if verbose
    while mt.is_a?(Mimetype) and mt != Mimetype
      STDERR.puts "  Trying #{mt}" if verbose
      mn = (mt.to_s.gsub(/[^a-z0-9]/i,"_") + "__gettext").to_sym
      if new_methods.include?( mn )
        begin
          rv = __send__( mn, filename, charset, layout )
          STDERR.puts "  OK" if verbose
          return rv
        rescue => e
          STDERR.puts(e, e.message, e.backtrace) unless quiet
        end
      end
      mt = mts.shift
    end
    STDERR.puts "  Text extraction failed" if verbose
    nil
  end
def extract_text ( filename , mimetype = MimeInfo . get ( filename . to_s ) , charset = nil , layout = false ) filename = filename . to_s mimetype = Mimetype [ mimetype ] unless mimetype . is_a? ( Mimetype ) mts = mimetype . ancestors mt = mts . shift new_methods = public_methods ( false ) STDERR . puts " Text extraction" if verbose while mt . is_a? ( Mimetype ) and mt != Mimetype STDERR . puts "  Trying #{mt}" if verbose mn = ( mt . to_s . gsub ( / [^a-z0-9] /i , "_" ) + "__gettext" ) . to_sym if new_methods . include? ( mn ) begin rv = __send__ ( mn , filename , charset , layout ) STDERR . puts "  OK" if verbose return rv rescue => e STDERR . puts ( e , e . message , e . backtrace ) unless quiet end end mt = mts . shift end STDERR . puts "  Text extraction failed" if verbose nil end
Extracts text from a file by guessing mimetype and calling matching
extractor methods (which mostly call external programs to do their bidding.)
Extracts text from a file by guessing mimetype and calling matching extractor methods ( which mostly call external programs to do their bidding . )
filename
<not_specific>
mimetype
<not_specific>
get
<not_specific>
to_s
<not_specific>
charset
<not_specific>
layout
<not_specific>