def extract(contents)
      file_text, matches = parse(contents)

      extracted_ruby = +''

      last_match = [0, 0]
      matches.each do |start_index, end_index|
        handle_region_before(start_index, last_match.last, file_text, extracted_ruby)

        extracted_ruby << extract_match(file_text, start_index, end_index)

        last_match = [start_index, end_index]
      end

      extracted_ruby << file_text[last_match.last..-1].gsub(/./, ' ')
      extracted_ruby.gsub!(/[^\S\r\n]+$/, '')

      # if we replaced <%== with <%= raw, try to shift the columns back to the
      # left so they match the original again
      extracted_ruby.gsub!(/   raw/, 'raw')

      extracted_ruby
    end
def extract(contents)
      file_text, matches = parse(contents)

      extracted_ruby = +''

      last_match = [0, 0]
      matches.each do |start_index, end_index|
        handle_region_before(start_index, last_match.last, file_text, extracted_ruby)

        extracted_ruby << extract_match(file_text, start_index, end_index)

        last_match = [start_index, end_index]
      end

      extracted_ruby << file_text[last_match.last..-1].gsub(/./, ' ')
      extracted_ruby.gsub!(/[^\S\r\n]+$/, '')

      # if we replaced <%== with <%= raw, try to shift the columns back to the
      # left so they match the original again
      extracted_ruby.gsub!(/   raw/, 'raw')

      extracted_ruby
    end
Extracts Ruby code from an ERB template.
 @return [String] The extracted ruby code