Class: UrlRegexp::Query
- Inherits:
-
Object
- Object
- UrlRegexp::Query
- Defined in:
- lib/url_regexp/query.rb
Instance Method Summary collapse
- #append(query) ⇒ Object
-
#initialize ⇒ Query
constructor
A new instance of Query.
- #to_regexp_s ⇒ Object
Constructor Details
#initialize ⇒ Query
Returns a new instance of Query.
3 4 5 |
# File 'lib/url_regexp/query.rb', line 3 def initialize @queries = [] end |
Instance Method Details
#append(query) ⇒ Object
7 8 9 10 |
# File 'lib/url_regexp/query.rb', line 7 def append(query) return if query.nil? @queries << query.to_s.split('&').reject(&:empty?) end |
#to_regexp_s ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/url_regexp/query.rb', line 12 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 "\\?(#{common_queries.permutation.map { |qs| "(.*&)?#{qs.join('.*&')}(&.*)?" }.join('|')})" elsif 1 == common_queries.size "\\?(.*&)?#{common_queries.first}(&.*)?" else '(\\?.*)?' end end |