Logan Capaldo
4/29/2005 12:43:00 AM
On 4/28/05, "Peña, Botp" <botp@delmonte-phil.com> wrote:
> Ara.T.Howard@noaa.gov [mailto:Ara.T.Howard@noaa.gov] wrote:
>
> # harp:~ > cal 2 2005
> # February 2005
> # Su Mo Tu We Th Fr Sa
> # 1 2 3 4 5
> # 6 7 8 9 10 11 12
> # 13 14 15 16 17 18 19
> # 20 21 22 23 24 25 26
> # 27 28
> #
> # harp:~ > cal 12 2005
> # December 2005
> # Su Mo Tu We Th Fr Sa
> # 1 2 3
> # 4 5 6 7 8 9 10
> # 11 12 13 14 15 16 17
> # 18 19 20 21 22 23 24
> # 25 26 27 28 29 30 31
> #
> #boy i love ruby.
>
> i took a deep breath there.
> I thought you were going to show us your cal.rb :-)
>
> A ruby quiz perhaps?
>
> kind regards -botp
>
> #
> #cheers.
> #
> #-a
> #--
>
>
Well here's mine:
#!/usr/bin/env ruby
require 'date'
month = ARGV[0] ? ARGV[0].to_i : Date.today.mon
year = ARGV[1] ? ARGV[1].to_i : Date.today.year
month_names = %w{January February March April May June July August September
October November Decemeber}
dow_banner = %{Su Mo Tu We Th Fr Sa}
days_in_mon = Date.civil(year, month, -1).day
# Print title:
print " " * ((dow_banner.length -
(year.to_s.length + 1 + month_names[month - 1].length)) / 2)
print "#{month_names[month - 1]} #{year}\n"
print "#{dow_banner}\n"
dow_counter = Date.civil(year, month, 1).wday
print " " * 3 * dow_counter
(1..days_in_mon).each { |i|
if i < 10
print " #{i}"
else
print "#{i}"
end
print " "
dow_counter += 1
if dow_counter % 7 == 0
print "\n"
end
}
print "\n"