Class: Restfulie::Client::Feature::OpenSearch::PatternMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/restfulie/client/feature/open_search/pattern_matcher.rb

Instance Method Summary collapse

Instance Method Details

#match(params, pattern) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/restfulie/client/feature/open_search/pattern_matcher.rb', line 5

def match(params, pattern)
  params = params.collect do |key, value|
    [key, value]
  end
  pattern = params.inject(pattern) do |pattern, p|
    what = "{#{p[0]}}"
    if pattern[what]
      pattern[what]= "#{p[1]}"
    end
    what = "{#{p[0]}?}"
    if pattern[what]
      pattern[what]= "#{p[1]}"
    end
    pattern
  end
  pattern.gsub(/\{[^\?]*\?\}/,"")
end