Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raven24/1893525 to your computer and use it in GitHub Desktop.
Save Raven24/1893525 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 MediaWiki table
require "rubygems"
require "bundler"
dia = '/home/florian/src/diaspora'
Dir.chdir dia
def allm obj
obj.methods.sort.each { |m|
puts m
}
end
class MediaWikiTable
def initialize(headers, data, maxwidth)
@headers = headers
@data = data
@maxwidth = maxwidth
end
def tbl_start
puts "{|"
end
def tbl_end
puts "|}"
end
def render_header
puts "!" + @headers.join( "\n!")
puts "|-"
end
def render_body
@data.each do |row|
puts "|" + row.map{ |cell|
dotdot = (cell.length > @maxwidth) ? "..." : ""
cell[0..@maxwidth].gsub(/[\n\s]+/, " ") + dotdot
}.join( "\n|")
puts "|-"
end
end
def render
tbl_start
render_header
render_body
tbl_end
end
end
def readgems
data = []
Bundler.rubygems.all_specs.each { |spec|
line = [
spec.name.to_s,
spec.version.to_s,
spec.description.to_s,
]
data.push line
}
headers = ['Name', 'Version', 'Description']
t = MediaWikiTable.new(headers, data, 120)
t.render
end
readgems
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment