Class: Service::Client::UrlPattern

Inherits:
Object
  • Object
show all
Defined in:
lib/service-client/url_pattern.rb

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ UrlPattern

Returns a new instance of UrlPattern.



2
3
4
5
6
7
# File 'lib/service-client/url_pattern.rb', line 2

def initialize(pattern)
  @pattern = pattern
  @pattern.scan(/:([^:]+):/).each do |placeholder|
    placeholders << placeholder.first.to_sym
  end
end

Instance Method Details

#filled_with(options) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/service-client/url_pattern.rb', line 9

def filled_with(options)
  url = @pattern.clone
  placeholders.each do |placeholder|
    url.gsub!(/:#{Regexp.escape(placeholder.to_s)}:/, options[placeholder].to_s)
  end
  url
end

#placeholdersObject



17
18
19
# File 'lib/service-client/url_pattern.rb', line 17

def placeholders
  @placeholders ||= []
end