This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: Walking Slide Numbers
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
See how Vincent Foley makes a local copy of the slides Matz put up:
require "open-uri"
BASE_URL = "http://www.rubyist.net/~matz/slides/oscon2005/mgp"
"00001".upto("00059") do |n|
puts "Fetching #{n}.html..."
File.open(n + ".html", "w") do |f|
f.write(open(BASE_URL + n + ".html").read)
end
end
The part I’m digging is that "00001".upto("00059"). I totally forgot about String.upto, which does a succ behind the scenes.
>> "r01".succ
=> "r02"
>> "r02".succ
=> "r03"
But if you want Matz’ slides, let’s also grab the JPEGs.
require "open-uri"
BASE_URL = "http://www.rubyist.net/~matz/slides/oscon2005/"
"mgp00001".upto("mgp00059") do |n|
['jpg', 'html'].each do |ext|
puts "Fetching #{n}.#{ext}..."
File.open("#{n}.#{ext}", "w") do |f|
f << open("#{BASE_URL}#{n}.#{ext}").read
end
end
end