Module: Garcon::UrlHelper
- Extended by:
- UrlHelper
- Defined in:
- lib/garcon/utility/url_helper.rb
Overview
Class methods that are added when you include Garcon
Instance Method Summary collapse
-
#unshorten(url, opts = {}) ⇒ Object
Unshorten a shortened URL.
-
#uri_join(*paths) ⇒ URI
Return a cleanly join URI/URL segments into a cleanly normalized URL that the libraries can use when constructing URIs.
Instance Method Details
#unshorten(url, opts = {}) ⇒ Object
Unshorten a shortened URL
57 58 59 60 61 62 63 64 65 |
# File 'lib/garcon/utility/url_helper.rb', line 57 def unshorten(url, opts= {}) = { max_level: opts.fetch(:max_level, 10), timeout: opts.fetch(:timeout, 2), use_cache: opts.fetch(:use_cache, true) } url = (url =~ /^https?:/i) ? url : "http://#{url}" __unshorten__(url, ) end |
#uri_join(*paths) ⇒ URI
Return a cleanly join URI/URL segments into a cleanly normalized URL that the libraries can use when constructing URIs. URI.join is pure evil.
36 37 38 39 40 41 42 |
# File 'lib/garcon/utility/url_helper.rb', line 36 def uri_join(*paths) return nil if paths.length == 0 leadingslash = paths[0][0] == '/' ? '/' : '' trailingslash = paths[-1][-1] == '/' ? '/' : '' paths.map! { |path| path.sub(/^\/+/, '').sub(/\/+$/, '') } leadingslash + paths.join('/') + trailingslash end |