rubygemstats 1.0.0
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.
- data/lib/rubygemstats.rb +53 -0
- metadata +46 -0
data/lib/rubygemstats.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "hpricot"
|
2
|
+
require "open-uri"
|
3
|
+
|
4
|
+
class Rubygem
|
5
|
+
attr_accessor :name
|
6
|
+
attr_accessor :version
|
7
|
+
attr_accessor :total_downloads
|
8
|
+
attr_accessor :for_this_version
|
9
|
+
attr_accessor :authors
|
10
|
+
|
11
|
+
def initialize(name)
|
12
|
+
stats = Rubygem.scrape(Rubygem.uri(name))
|
13
|
+
@name = name
|
14
|
+
@version = stats[:version]
|
15
|
+
@total_downloads = stats[:total_downloads]
|
16
|
+
@for_this_version = stats[:for_this_version]
|
17
|
+
@authors = stats[:authors]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.uri(name)
|
21
|
+
"http://rubygems.org/gems/#{name}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.scrape(uri)
|
25
|
+
doc = open(uri){|f|Hpricot(f)}
|
26
|
+
g = self.gem_name(uri)
|
27
|
+
v = self.version(doc)
|
28
|
+
td = self.total_downloads(doc)
|
29
|
+
ftv = self.for_this_version(doc)
|
30
|
+
a = self.authors(doc)
|
31
|
+
{:gem_name => g, :version => v, :total_downloads => td, :for_this_version => ftv, :authors => a}
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.gem_name(uri)
|
35
|
+
uri.scan(/\/gems\/\w+/).first.split("/")[-1]
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.version(doc)
|
39
|
+
doc.search("//div[@class='versions']").search("//a").first.attributes["href"].split("/")[-1]
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.total_downloads(doc)
|
43
|
+
doc.search("//div[@class='downloads counter']").search("//strong").first.inner_html.gsub(",","").to_i
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.for_this_version(doc)
|
47
|
+
doc.search("//div[@class='downloads counter']").search("//strong")[1].inner_html.gsub(",","").to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.authors(doc)
|
51
|
+
doc.search("//div[@class='authors info-item']").search("//p").inner_html.split(", ")
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubygemstats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Benjamin Godlove
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-16 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Scrape gem information from http://rubygems.org.
|
15
|
+
email: bgodlove88@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/rubygemstats.rb
|
21
|
+
homepage: http://github.com/brg8/rubygemstats
|
22
|
+
licenses:
|
23
|
+
- GNU
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.23
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Scrape gem information from http://rubygems.org.
|
46
|
+
test_files: []
|