Created
October 11, 2011 23:49
-
-
Save softwaregravy/1279822 to your computer and use it in GitHub Desktop.
Day Map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DayMap | |
day_array = [] | |
Date::DAYNAMES.each_with_index{|d, i| day_array << [d, i]} | |
reverse_day_array = [] | |
Date::DAYNAMES.each_with_index{|d, i| reverse_day_array << [i, d]} | |
DAY_MAP = Hash[day_array] | |
REVERSE_MAP = Hash[reverse_day_array] | |
class << self | |
def day_for_int(i) | |
REVERSE_MAP[i.to_i] | |
end | |
def int_for_day(day) | |
DAY_MAP[day.to_s.capitalize] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment