Class: SearchResult
- Inherits:
-
Object
- Object
- SearchResult
- Defined in:
- lib/baidu.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(body, baseuri, pagenumber = nil) ⇒ SearchResult
constructor
A new instance of SearchResult.
-
#rank(host) ⇒ Object
return the top rank number from @ranks with the input host.
-
#ranks_for(specific_host) ⇒ Object
返回当前页中host满足条件的结果.
Constructor Details
#initialize(body, baseuri, pagenumber = nil) ⇒ SearchResult
Returns a new instance of SearchResult.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/baidu.rb', line 16 def initialize(body,baseuri,pagenumber=nil) @body = Nokogiri::HTML body @baseuri = baseuri # @host = URI(baseuri).host if pagenumber.nil? @pagenumber = 1 else @pagenumber = pagenumber end end |
Instance Method Details
#rank(host) ⇒ Object
return the top rank number from @ranks with the input host
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/baidu.rb', line 40 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满足条件的结果
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/baidu.rb', line 28 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 |