class Query

Public Class Methods

new(opt, query) click to toggle source
# File bin/podcatcher, line 2155
def initialize(opt, query)
        @@ATOM_NS = Regexp.new '^http://purl.org/atom/ns#'
        @@ITUNES_NS = 'http://www.itunes.com/dtds/podcast-1.0.dtd'
        @opt = opt
        if query
                @query = query.downcase.split
                @query = nil if @query.size == 0
        end
        @stats = Stats.new opt.dir
end

Public Instance Methods

Private Instance Methods

fetchdoc(link) click to toggle source
# File bin/podcatcher, line 2392
def fetchdoc(link)
        doc = ""
        1.upto(@opt.retries) do |i|
                begin 
                        if link.url =~ %r{^http:} or link.url =~ %r{^ftp:}
                                if link.referrer and (link.referrer =~ %r{^http:} or link.referrer =~ %r{^ftp:})
                                        open(link.url, "User-Agent" => USER_AGENT, "Referer" => link.referrer) do |f|
                                                break if f.content_type.index "audio/"
                                                break if f.content_type.index "video/"
                                                f.each_line() do |e|
                                                        doc += e
                                                end
                                        end
                                else 
                                        open(link.url, "User-Agent" => USER_AGENT) do |f|
                                                break if f.content_type.index "audio/"
                                                break if f.content_type.index "video/"
                                                f.each_line() do |e|
                                                        doc += e
                                                end
                                        end
                                end
                        else 
                                open(link.url) do |f|
                                        f.each_line() do |e|
                                                doc += e
                                        end
                                end
                        end
                        break
                rescue Interrupt
                rescue SystemExit
                        break
                rescue Exception
                end 
                $stderr.puts "Attempt #{i} aborted" if @opt.verbose
                doc = ""
                sleep 5
        end
        res = nil
        begin 
                res = Document.new doc
        rescue Exception
        end 
        res = nil unless res and res.root
        res
end
relevance_of(meta) click to toggle source
# File bin/podcatcher, line 2377
def relevance_of(meta)
        return 0 unless meta
        unless meta.kind_of? String #Text todo: resolve entities
                meta = meta.value
        end
        meta = meta.downcase
        meta = meta.split
        res = 0
        @query.each() do |e|
                meta.each() do |e2|
                        res += 1 if e2.index(e)
                end
        end
        res
end