Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/motion-resource/string.rb
Instance Method Summary collapse
- #build_query_string!(params = {}) ⇒ Object
-
#fill_url_params(params = {}, delegate = nil) ⇒ Object
Takes in a hash and spits out the formatted string Checks the delegate first.
- #insert_extension!(extension) ⇒ Object
Instance Method Details
#build_query_string!(params = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/motion-resource/string.rb', line 25 def build_query_string!(params = {}) return self if params.keys.empty? # fake a url so we avoid regex nastiness with URL's url = NSURL.URLWithString("http://blah.com/#{self}") # build our query string (needs encoding support!) query_string = params.map{|k,v| "#{k}=#{v}"}.join('&') if url.query.nil? || url.query.empty? # strip the beginning / and add the query self.replace "#{url.path[1..-1]}?#{query_string}" else self.replace "#{url.path[1..-1]}?#{url.query}&#{query_string}" end end |
#fill_url_params(params = {}, delegate = nil) ⇒ Object
Takes in a hash and spits out the formatted string Checks the delegate first
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/motion-resource/string.rb', line 4 def fill_url_params(params = {}, delegate = nil) params ||= {} split = self.split '/' url = split.collect { |path| ret = path if path[0] == ':' path_sym = path[1..-1].to_sym curr = nil if delegate && delegate.respond_to?(path_sym) curr = delegate.send(path_sym) end ret = (curr || params.delete(path_sym) || path).to_s end ret }.join '/' url.build_query_string! params end |
#insert_extension!(extension) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/motion-resource/string.rb', line 39 def insert_extension!(extension) return self if extension.blank? url = NSURL.URLWithString(self) extension = extension.gsub(".", "") self.replace url.URLByAppendingPathExtension(extension).absoluteString end |