lib/timeliness/format_set.rb in timeliness-0.3.2 vs lib/timeliness/format_set.rb in timeliness-0.3.3
- old
+ new
@@ -26,11 +26,11 @@
@regexp = Regexp.new("^(?:#{regexp_string.chop})$")
self
end
def match(string, format_string=nil)
- format = @formats_hash[format_string] if format_string
+ format = single_format(format_string) if format_string
match_regexp = format && format.regexp || @regexp
if match_data = match_regexp.match(string)
index = match_data.captures.index(string)
start = index + 1
@@ -38,7 +38,10 @@
format ||= @match_indexes[index]
format.process(*values)
end
end
+ def single_format(format_string)
+ @formats_hash[format_string] || Format.new(format_string).compile!
+ end
end
end