Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created March 12, 2013 09:54
Show Gist options
  • Select an option

  • Save peterhellberg/5141654 to your computer and use it in GitHub Desktop.

Select an option

Save peterhellberg/5141654 to your computer and use it in GitHub Desktop.
A simple little scraper for the YC List
require 'open-uri'
require 'nokogiri'
module YCList
class << self
def url
'http://yclist.com/'
end
def scrape
doc = Nokogiri::HTML(open(url))
@companies = doc.css('#companies table tbody tr').map do |row|
Company.new(*row.children.map(&:text)[1..-1])
end
end
def companies
@companies || scrape && @companies
end
def all(filter = //, field = :name)
companies.select { |c| c.send(field).match filter }
end
def one(*args)
all(*args).sample
end
def alive
status ''
end
def dead
status 'Dead'
end
def exited
status 'Exited'
end
def method_missing(m, *args, &block)
fields = %i(name url yc_class status description year)
all(args.first, m) if fields.include?(m)
end
end
class Company
attr_reader :name, :url, :yc_class, :status, :description, :year
def initialize(name, url, yc_class, status, description)
@name = name
@url = url
@yc_class = yc_class
@status = status
@description = description
@year = yc_class.gsub(/^W|S/, "20").to_i
end
def to_s
name
end
alias :inspect :to_s
end
end
@peterhellberg
Copy link
Author

Usage

# All of the companies
YCList.companies

# All companies with a description that includes the word "iPhone"
YCList.description 'iPhone'

# All the dead companies
YCList.dead

# The company name for one of the companies in the summer class of '05
YCList.one('S05', :yc_class).name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment