Module: Imglab::Url::Utils
Constant Summary collapse
- NORMALIZE_PATH_PREFIX_REGEXP =
Regexp.compile(/\A\/*/)
- NORMALIZE_PATH_SUFFIX_REGEXP =
Regexp.compile(/\/*$/)
- WEB_URI_SCHEMES =
%w[https http].freeze
Instance Method Summary collapse
-
#normalize_params(params) ⇒ Hash
Returns normalized params, transforming keys with undercores to hyphens.
-
#normalize_path(path) ⇒ String
Returns a normalized path where suffix and prefix slashes are removed.
-
#web_uri?(uri) ⇒ Boolean
Returns a boolean value indicating whether a string is a valid HTTP/HTTPS URI or not.
Instance Method Details
#normalize_params(params) ⇒ Hash
Returns normalized params, transforming keys with undercores to hyphens.
22 23 24 25 26 |
# File 'lib/imglab/url/utils.rb', line 22 def normalize_params(params) params.inject({}) do |normalized_params, value| normalized_params.merge(normalize_param(dasherize(value[0]), value[1])) end end |
#normalize_path(path) ⇒ String
Returns a normalized path where suffix and prefix slashes are removed.
14 15 16 |
# File 'lib/imglab/url/utils.rb', line 14 def normalize_path(path) path.gsub(NORMALIZE_PATH_PREFIX_REGEXP, "").gsub(NORMALIZE_PATH_SUFFIX_REGEXP, "") end |
#web_uri?(uri) ⇒ Boolean
Returns a boolean value indicating whether a string is a valid HTTP/HTTPS URI or not.
32 33 34 35 36 |
# File 'lib/imglab/url/utils.rb', line 32 def web_uri?(uri) WEB_URI_SCHEMES.include?(URI.parse(uri).scheme) rescue URI::Error false end |