Permalink
Browse files

add script for "RubyGems Guides"

  • Loading branch information...
1 parent 146febd commit 0b0efeadc40dcba235f023ad6d4c75b62649908d @banyan banyan committed Jul 11, 2012
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)

0 comments on commit 0b0efea

Please sign in to comment.