11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/howkast/ext/string.rb', line 11
def parse
rfc2822 = "(#{Time::RFC2822_DAY_NAME.join('|')}, )? \d{1,2} #{Time::RFC2822_MONTH_NAME.join('|')} \d{4,4} \d{2,2}:\d{2,2}:\d{2,2} [+-]\d{4,4}"
ansi = "#{Time::RFC2822_DAY_NAME.join('|')} #{Time::RFC2822_MONTH_NAME.join('|')} +\d{1,2} \d{2,2}:\d{2,2}:\d{2,2} [A-Z]{3,3} \d{4,4}"
case self
when /^[+-]?\d+$/u
to_i
when /^[+-]?\d+\.\d+/u
to_f
when /^(true|false)$/iu
self =~ /^true$/iu ? true : false
when /^#{rfc2822}|#{ansi}$/u
Time.parse(self) rescue self
else
self
end
end
|