loading...
Cover image for Are you the next (Ruby) Thanos?

Are you the next (Ruby) Thanos?

daviducolo profile image Davide Santangelo ・2 min read

for fun, I asked myself:

Is there a way to know who is the best Ruby gem maker on the planet? Who is entitled to the title of "Gemminator"?

so I decided to write a Ruby script to take some information and get a score.

Score

The score GS ( Gemminator Score ) is defined by the sum of two values. The RGS (RubyGems Score) and GHS (GitHub Score).

RGS

sum(downloads) + (1.0 - 1.0/count(gems))

GHS

sum(stars + forks) + (1.0 - 1.0/count(repositories))

GS

GS = RGS + GHS 

OK! Let's start writing some code!

Gems

for data collection I use two gems that are:

Gems - Ruby wrapper for the RubyGems.org API https://rubygems.org
Octokit - Ruby toolkit for the GitHub API http://octokit.github.io/octokit.rb/

Script

you need a GitHub personal access token to avoid rate limit. A personal access token is a token you have generated (https://github.com/settings/tokens) that can be used to access the GitHub API.

  require 'octokit'
  require 'gems'

  downloads_count = 0
  stars_count = 0
  forks_count = 0

  client = Octokit::Client.new(access_token: ARGV[1])
  gems = Gems.gems(ARGV[0])

  downloads = gems.map do |gem| 
    gem['downloads']
  end

fetch counters

downloads_count = downloads.sum

gems.select! do |gem| 
  gem['homepage_uri'].to_s.start_with? 'https://github.com'
end

github_repos = gems.map do |gem|
  client.repo(gem['homepage_uri'].split("/").last(2).join("/")) rescue nil
end.compact

github_repos.map do |repo|
  stars_count += repo.stargazers_count
  forks_count += repo.forks
end

get results

rgs = downloads_count + (1.0 - 1.0 / gems.size)
ghs = stars_count + forks_count + (1.0 - 1.0 / github_repos.size)

gs = rgs + ghs

Examples

ruby gemminator.rb <rubygem_username> <github_access_token>

https://rubygems.org/profiles/davidesantangelo

➜ ruby gemminator.rb davidesantangelo <token>
110751.675

https://rubygems.org/profiles/ankane

➜ ruby gemminator.rb ankane <token>
43355989.97872341

https://rubygems.org/profiles/sferik

➜ ruby gemminator.rb sferik <token>
1519272118.937439

Note

of course, it is a basic demo script without the management of all the exceptions/optimizations that can be found.

If you liked this post follow me on Twitter!

Posted on May 12 by:

daviducolo profile

Davide Santangelo

@daviducolo

developer - dad. APIs specialist, In love with #ruby, #rails and #python - developer at @getchorally

Discussion

markdown guide
 

It should have some weightage on if gem is maintained or not, probably based on recent pr or commits.

 

Of course! Thanks for the feedback. Obviously as explained it is a script written in a short time that does not take into account various factors, but thanks I'll keep it in mind.