Sha256: df0174eddf95bcf95b0826da88073b4a96b34ac2cf4b7692fc9884d16829130d
Contents?: true
Size: 673 Bytes
Versions: 26
Compression:
Stored size: 673 Bytes
Contents
#!/usr/bin/env ruby # frozen_string_literal: true require 'benchmark/ips' PATH = '/../../..../...//.....//lorem/ipsum//dolor///sit.xyz' def sanitize_with_regex "/#{PATH.gsub(%r!/{2,}!, '/').gsub(%r{\.+/|\A/+}, '')}" end def sanitize_with_builtin "/#{PATH}".gsub('..', '/').gsub('./', '').squeeze('/') end if sanitize_with_regex == sanitize_with_builtin Benchmark.ips do |x| x.report('sanitize w/ regexes') { sanitize_with_regex } x.report('sanitize w/ builtin') { sanitize_with_builtin } x.compare! end else puts "w/ regexes: #{sanitize_with_regex}" puts "w/ builtin: #{sanitize_with_builtin}" puts '' puts 'Thank you. Do try again :(' end
Version data entries
26 entries across 26 versions & 1 rubygems