Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/spider_bot/string/time.rb
Instance Method Summary collapse
-
#parse_time(zone = nil) ⇒ Object
Parse content to local time.
Instance Method Details
#parse_time(zone = nil) ⇒ Object
Parse content to local time
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/spider_bot/string/time.rb', line 13 def parse_time(zone = nil) Time.zone = zone.nil? ? "UTC" : zone @time_config = DATE_CONFIG["date"]["time"] @month_config = DATE_CONFIG["date"]["month"] @other_config = DATE_CONFIG["date"]["other"] @time_str = @time_config.values.join("|") @time_regex = %r"\d+[\s|\S]*(?:#{@time_str})\s*(?:#{@other_config["ago"]})" @today_regex = %r"#{@other_config["today"]}\s*\d{1,2}:\d{1,2}" case self when @time_regex parse_date_ago when @today_regex parse_today else parse_date end end |