Is there a way in Ruby to calculate the number of weeks(ISO 8601) for a given year? I\'m currently using a lookup table and I\'d like to stop using it.
require 'date'
def num_weeks(year = Date.today.year)
# all years starting with Thursday, and leap years starting with Wednesday have 53 weeks
# http://en.wikipedia.org/wiki/ISO_week_date#Last_week
d = Date.new(year, 1, 1)
return 53 if d.wday == 4
return 53 if d.leap? and d.wday == 3
52
end