Skip to content

Instantly share code, notes, and snippets.

@koseki
Created June 5, 2010 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koseki/426852 to your computer and use it in GitHub Desktop.
Save koseki/426852 to your computer and use it in GitHub Desktop.
generate URI Schemes RFC list
#! /usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'nokogiri'
require 'pp'
styles = {
"PROPOSED STANDARD" => "background-color:#6666FF;color:white;",
"EXPERIMENTAL" => "background-color:#EEEE00;color:white",
"INFORMATIONAL" => "background-color:#FFAA00;color:white",
"DRAFT STANDARD" => "background-color:#44DDDD;color:white",
"HISTORIC" => "background-color:#666666;color:white",
}
source = open("http://www.ietf.org/download/rfc-index.txt") {|io| io.read }
status = {}
source.scan(/^(\d{4}) (.+?)\n\n/m).each do |data|
num = data[0]
txt = data[1]
txt.gsub!(/\s+/m, " ")
txt =~ /\(Status: (.+?)\)/
stat = $1
status[num] = [txt, stat]
end
doc = Nokogiri::HTML(open("http://www.iana.org/assignments/uri-schemes.html"))
trs = doc.xpath("//tbody//tbody/tr")
schemes = []
trs.each do |tr|
tds = tr.xpath("td")
next unless tds[2].text =~ /\A\[RFC(\d+)\]\z/
num = $1
scheme = tds[0].text
stat = status[num][1].strip
style = styles[stat]
txt = status[num][0]
print %{- <a href="http://tools.ietf.org/html/rfc#{num}">RFC#{num}</a> <strong>#{scheme}</strong> }
puts %{[http://tools.ietf.org/html/rfc#{num}:bookmark]}
puts %{-- <span style="#{style}">#{stat}</span>}
puts %{-- #{txt}}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment