Created
August 27, 2010 01:21
-
-
Save redtettemer/552581 to your computer and use it in GitHub Desktop.
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
# Parse date scraped from HTML into a proper date object for the database | |
def parse_date(text) | |
text = text.text.to_s | |
text = text.gsub(/,/, ' ') | |
pieces = text.split(' ') | |
pieces_to_remove = ["on", "at", "@"] | |
pieces = pieces - pieces_to_remove | |
month = pieces[1] | |
case month | |
when "Jan" | |
month = 1 | |
when "Feb" | |
month = 2 | |
when "Mar" | |
month = 3 | |
when "Apr" | |
month = 4 | |
when "May" | |
month = 5 | |
when "Jun" | |
month = 6 | |
when "Jul" | |
month = 7 | |
when "Aug" | |
month = 8 | |
when "Sep" | |
month = 9 | |
when "Oct" | |
month = 10 | |
when "Nov" | |
month = 11 | |
when "Dec" | |
month = 12 | |
else | |
p "Date detection barfed for " + month | |
end | |
day = pieces[2].to_i | |
year = pieces[3].to_i | |
time = pieces[4].to_i | |
meridian = pieces[5].to_i | |
unlocked_date = Date.new(year, month, day) | |
unlocked_date | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment