class Date
Purpose: Extend the date parsing capabilities of Ruby to work with dates with international month names.
Usage:
Date.parse_international(date_string)
DateTime.parse_international(date_string)
date_string.to_international_date
Notes: 1) This routine works by substituting your local month names (as defined by Date::MONTHNAMES) for the
international names when they occur in the date_string.
2) As distributed, this code works for French, German, Italian, and Spanish. You must add the month
names for any additional languages you wish to handle.
Constants
- MONTH_TRANSLATIONS
Public Class Methods
parse_international(string)
click to toggle source
# File lib/holiday_scraper/parser.rb, line 86 def self.parse_international(string) parse(month_to_english(string)) end
Private Class Methods
make_hash(names)
click to toggle source
# File lib/holiday_scraper/parser.rb, line 92 def self.make_hash(names) names.inject({}) {|result, name| result[name] = MONTHNAMES[result.count+1] ; result } end
month_to_english(string)
click to toggle source
# File lib/holiday_scraper/parser.rb, line 102 def self.month_to_english(string) month_from = string[/[^\s\d,.]+/i] # Search for a month name if month_from month_to = MONTH_TRANSLATIONS[month_from.downcase] # Look up the translation return string.sub(month_from, month_to.to_s) if month_to end return string end