Created
July 6, 2024 08:22
-
-
Save Dahie/923df236ee7fc255441a2ee9f97680fe to your computer and use it in GitHub Desktop.
gem-what?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This script reads your Gemfile and fetches the dependent gem's descriptions from Rubygems. | |
# This helps me to quickly 'learn' a project, but looking up gems more easy. | |
# | |
# Usage: | |
# - Download & place in project folder | |
# - `gem install wombat` | |
# - `ruby gemwhat.rb Gemfile` | |
require 'wombat' | |
body = File.read(ARGV[0]) | |
gems_names = body.scan(/^\s*gem ["']([\d\w_-]*)["']/).flatten | |
fetched_gem_data = gems_names.map do |name| | |
sleep 0.5 # I want to be polite and not hit RubyGems too hard | |
Wombat.crawl do | |
base_url "https://rubygems.org" | |
path "/gems/#{name}" | |
title css: '.page__heading' | |
description css: ".gem__desc" | |
end | |
end | |
html = "<html><head><title>Gem Listing</title></head><body><h1>Gem listing</h1>" | |
fetched_gem_data.each do |gem| | |
puts "# #{gem['title'].squeeze}\n\n#{gem['description']}\n\n" | |
html << "<h2>#{gem['title'].squeeze.gsub("\n", "")}</h2>" | |
html << "<p>#{gem['description']}</p>" | |
end | |
html << "</body></html>" | |
File.write("Gemfile.html", html) | |
`open Gemfile.html` # open in browser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment