class Rubygem
Attributes
for_this_version[RW]
name[RW]
total_downloads[RW]
version[RW]
Public Class Methods
for_this_version(doc)
click to toggle source
# File lib/rubygemstats.rb, line 46 def self.for_this_version(doc) doc.search("//div[@class='downloads counter']").search("//strong")[1].inner_html.gsub(",","").to_i end
gem_name(uri)
click to toggle source
# File lib/rubygemstats.rb, line 34 def self.gem_name(uri) uri.scan(/\/gems\/\w+/).first.split("/")[-1] end
new(name)
click to toggle source
# File lib/rubygemstats.rb, line 11 def initialize(name) stats = Rubygem.scrape(Rubygem.uri(name)) @name = name @version = stats[:version] @total_downloads = stats[:total_downloads] @for_this_version = stats[:for_this_version] @authors = stats[:authors] end
scrape(uri)
click to toggle source
# File lib/rubygemstats.rb, line 24 def self.scrape(uri) doc = open(uri){|f|Hpricot(f)} g = self.gem_name(uri) v = self.version(doc) td = self.total_downloads(doc) ftv = self.for_this_version(doc) a = self.authors(doc) {:gem_name => g, :version => v, :total_downloads => td, :for_this_version => ftv, :authors => a} end
total_downloads(doc)
click to toggle source
# File lib/rubygemstats.rb, line 42 def self.total_downloads(doc) doc.search("//div[@class='downloads counter']").search("//strong").first.inner_html.gsub(",","").to_i end
uri(name)
click to toggle source
# File lib/rubygemstats.rb, line 20 def self.uri(name) "http://rubygems.org/gems/#{name}" end
version(doc)
click to toggle source
# File lib/rubygemstats.rb, line 38 def self.version(doc) doc.search("//div[@class='versions']").search("//a").first.attributes["href"].split("/")[-1] end