lib/url_regexp/query.rb in url_regexp-0.1.2 vs lib/url_regexp/query.rb in url_regexp-0.1.3

- old
+ new

@@ -1,24 +1,31 @@ module UrlRegexp class Query - def initialize + def initialize(options = {}) + @include_nil = false @queries = [] + @options = options end def append(query) - return if query.nil? - @queries << query.to_s.split('&').reject(&:empty?) + query = query.to_s + if query.empty? + @include_nil = true + return + end + @queries << query.split('&') end def to_regexp_s common_queries = @queries.reduce { |a, e| a & e } || [] common_queries = common_queries.map { |q| Regexp.quote(q) } - if 1 < common_queries.size + regexp_s = if 1 < common_queries.size "\\?(#{common_queries.permutation.map { |qs| "(.*&)?#{qs.join('.*&')}(&.*)?" }.join('|')})" elsif 1 == common_queries.size "\\?(.*&)?#{common_queries.first}(&.*)?" else '(\\?.*)?' end + @include_nil ? "(#{regexp_s})?" : regexp_s end end end