Created
July 30, 2008 14:54
-
-
Save zmalltalker/3270 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'rubygems' | |
require 'hpricot' | |
require 'open-uri' | |
class Gist | |
attr_accessor :gist_id, :title, :author | |
def self.find_all(author="zmalltalker") | |
result = [] | |
doc = Hpricot(open("http://gist.github.com/#{author}")) | |
(doc/"div.file").each do |file| | |
link = (file/"div.info/span/a").first | |
g = new | |
g.author = author | |
g.gist_id = link[:href].split("/").last | |
data = (file/"//div.highlight").inner_text[0,50] | |
g.title = data | |
result << g | |
end | |
return result | |
end | |
def contents | |
@contents ||= load_attributes | |
end | |
def to_s | |
result = [] | |
result << "Gist ##{gist_id} by #{author} #{raw_link}" | |
result << "=" * 80 | |
result << contents | |
result << "\n" * 5 | |
result.join("\n") | |
end | |
def load_attributes | |
if link = raw_link | |
doc = open(link).read | |
return doc | |
end | |
end | |
def raw_link | |
@raw_link ||= find_raw_link | |
end | |
def find_raw_link | |
doc = Hpricot(open("http://gist.github.com/#{gist_id}")) | |
links = (doc/"a") | |
links.each do |m| | |
if m.inner_html == 'raw' | |
return "http://gist.github.com#{m[:href]}" | |
end | |
end | |
end | |
end | |
gists = Gist.find_all | |
gists.each do |g| | |
puts g | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment