lib/timeliness/format_set.rb
# Compiles the formats into one big regexp. Stores the index of where
# each format's capture values begin in the matchdata.
Compiles the formats into one big regexp. Stores the index of where
each format's capture values begin in the matchdata.
Compiles the formats into one big regexp . Stores the index of where each format ' s capture values begin in the matchdata .
def compile!
      regexp_string = ''
      @formats.inject(0) { |index, format_string|
        format = Format.new(format_string).compile!
        @formats_hash[format_string] = format
        @match_indexes[index] = format
        regexp_string = "#{regexp_string}(#{format.regexp_string})|"
        index + format.token_count + 1 
      }
      @regexp = %r[\A(?:#{regexp_string.chop})\z]
      self
    end
def compile! regexp_string = '' @formats . inject ( 0 ) { | index , format_string | format = Format . new ( format_string ) . compile! @formats_hash [ format_string ] = format @match_indexes [ index ] = format regexp_string = "#{regexp_string}(#{format.regexp_string})|" index + format . token_count + 1 } @regexp = %r[ \A (?: #{ regexp_string . chop } ) \z ] self end
Compiles the formats into one big regexp.
Compiles the formats into one big regexp .
# add one for wrapper capture