Skip to content

Instantly share code, notes, and snippets.

@redtettemer
Created August 27, 2010 01:21
Show Gist options
  • Save redtettemer/552581 to your computer and use it in GitHub Desktop.
Save redtettemer/552581 to your computer and use it in GitHub Desktop.
# 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