Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #15 from banyan/add-rubygems-guide

add script for "RubyGems Guides"
  • Loading branch information...
commit 1a856aae39a6bc09a69c8b5b94ec420cca310e79 2 parents 146febd + 0b0efea
@mizzy authored
Showing with 29 additions and 0 deletions.
  1. +29 −0 misc/rubygems_guides.rb
View
29 misc/rubygems_guides.rb
@@ -0,0 +1,29 @@
+%w(uri json nokogiri curb cgi).each {|g| require g }
+
+root = 'http://guides.rubygems.org'
+book = {
+ :title => 'RubyGems Guides',
+ :authors => %w( rubygems ),
+ :cover_image => 'http://guides.rubygems.org/images/logo.png',
+ :content_xpath => '//section[@id="chapters"]',
+ :chapters => []
+}
+
+def curl(url)
+ c = Curl::Easy.new(url.to_s)
+ c.follow_location = true
+ c.perform
+ c.body_str
+end
+
+doc = Nokogiri::HTML(curl(root))
+doc.xpath('//section[@id="chapters"]/h2/a').each do |a|
+ chapter_url = URI(root) + a[:href]
+ chapter = {
+ :uri => chapter_url,
+ :title => a.text,
+ }
+ book[:chapters] << chapter
+end
+
+puts JSON.pretty_generate(book)
Please sign in to comment.
Something went wrong with that request. Please try again.