baidu 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/baidu.rb +7 -2
  2. metadata +1 -1
@@ -105,8 +105,13 @@ class BaiduResult
105
105
  @page = page
106
106
  end
107
107
 
108
- def ranks
109
- @ranks ||= @page.search("//table[@class=\"result\"]").map{|table|@page.search("//table[@id=\"#{table['id']}\"]//span[@class=\"g\"]").first}.map{|rank|rank.text unless rank.nil?}
108
+ def ranks(host=nil)
109
+ @ranks ||= @page.search("//table[@class=\"result\"]").map{|table|@page.search("//table[@id=\"#{table['id']}\"]//span[@class=\"g\"]").first}.map{|rank|URI('http://'+rank.text.strip.split(/\s/).first).host unless rank.nil?}
110
+ if host.nil?
111
+ @ranks
112
+ else
113
+ @ranks.each_with_index.map{|h,i| i if !h.nil? and h==host}.compact
114
+ end
110
115
  end
111
116
 
112
117
  #look up a word and get the rank of a uri with $host
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baidu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: