Skip to content

Instantly share code, notes, and snippets.

@groovehunter
Created January 8, 2012 21:34
Show Gist options
  • Save groovehunter/1579777 to your computer and use it in GitHub Desktop.
Save groovehunter/1579777 to your computer and use it in GitHub Desktop.
Display table with all gems in a bundle, each with ie. summary and description, render in markdown table
require "rubygems"
require "bundler"
dia = '/var/www/vhosts/diaspora'
Dir.chdir dia
def allm obj
obj.methods.sort.each { |m|
puts m
}
end
class MarkdownTable
def initialize(headers, data, cellwidths)
@headers = headers
@data = data
@cellwidths = cellwidths
end
def render_header
hline = []
hline2 = []
for i in 0..@headers.length-1 do
hline.push @headers[i].ljust(@cellwidths[i])
hline2.push '-'*@cellwidths[i]
end
puts hline.join(' | ')
puts hline2.join(' | ')
end
def render_body
for line in @data
puts line.join('|')
end
end
def render
render_header
render_body
end
end
def readgems
data = []
Bundler.rubygems.all_specs.each { |spec|
line = [
spec.spec_name.to_s,
spec.summary.to_s,
]
desc = spec.description.to_s[0..100].gsub("\n"," - ")
line.push "#{desc}"
data.push line
}
headers = ['Name', 'Summary', 'Description']
cellwidths = [ 10, 20, 80]
t = MarkdownTable.new(headers, data, cellwidths)
t.render
end
readgems
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment