Class: Query::Result::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/query/result/base.rb

Direct Known Subclasses

Baidu, BaiduMobile, Qihoo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ Base

Returns a new instance of Base.



5
6
7
8
# File 'lib/query/result/base.rb', line 5

def initialize(page)
    @page = Nokogiri::HTML page
    @pagenumber = 1
end

Instance Attribute Details

#baseuriObject

Returns the value of attribute baseuri.



4
5
6
# File 'lib/query/result/base.rb', line 4

def baseuri
  @baseuri
end

#pagenumberObject

Returns the value of attribute pagenumber.



4
5
6
# File 'lib/query/result/base.rb', line 4

def pagenumber
  @pagenumber
end

#perpageObject

Returns the value of attribute perpage.



4
5
6
# File 'lib/query/result/base.rb', line 4

def perpage
  @perpage
end

Instance Method Details

#rank(host) ⇒ Object

return the top rank number from @ranks with the input host



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/query/result/base.rb', line 37

def rank(host)#on base of ranks
    ranks.each do |id,line|
        id = id.to_i
        if host.class == Regexp
            return id if line['host'] =~ host
        elsif host.class == String
            return id if line['host'] == host
        end
    end
    return nil
end

#ranks_for(specific_host) ⇒ Object

返回当前页中host满足条件的结果



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/query/result/base.rb', line 25

def ranks_for(specific_host)
    host_ranks = Hash.new
    ranks.each do |id,line|
        if specific_host.class == Regexp
            host_ranks[id] = line if line['host'] =~ specific_host
        elsif specific_host.class == String
            host_ranks[id] = line if line['host'] == specific_host
        end
    end
    host_ranks
end

#wholeObject

def initialize(page,baseuri,pagenumber=1,perpage=100)

@page = Nokogiri::HTML page
@baseuri = baseuri
# @host = URI(baseuri).host
@pagenumber = pagenumber
@perpage = perpage

end



16
17
18
19
20
21
22
23
# File 'lib/query/result/base.rb', line 16

def whole
    {
        'ads_top'=>ads_top,
        'ads_right'=>ads_right,
        'ads_bottom'=>ads_bottom,
        'ranks'=>ranks
    }
end