Class: NormalizeUrl::Normalizer
- Inherits:
-
Object
- Object
- NormalizeUrl::Normalizer
- Defined in:
- lib/normalize_url/normalizer.rb
Constant Summary collapse
- TRACKING_QUERY_PARAMS =
%w[ utm_source utm_medium utm_term utm_content utm_campaign sms_ss awesm xtor PHPSESSID ].to_set.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(original_uri, options = {}) ⇒ Normalizer
constructor
A new instance of Normalizer.
- #normalize ⇒ Object
Constructor Details
#initialize(original_uri, options = {}) ⇒ Normalizer
Returns a new instance of Normalizer.
20 21 22 23 24 25 26 27 |
# File 'lib/normalize_url/normalizer.rb', line 20 def initialize(original_uri, ={}) @uri = Addressable::URI.parse(original_uri).normalize @options = fail_uri "only absolute URLs can be normalized" unless uri.absolute? fail_uri "only HTTP/HTTPS URLs can be normalized" unless uri.scheme =~ /https?/ rescue Addressable::URI::InvalidURIError fail_uri "#{original_uri.inspect} is not a URL" end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/normalize_url/normalizer.rb', line 6 def @options end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
6 7 8 |
# File 'lib/normalize_url/normalizer.rb', line 6 def uri @uri end |
Instance Method Details
#normalize ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/normalize_url/normalizer.rb', line 29 def normalize process :remove_trailing_slash process :remove_repeating_slashes process :remove_hash process_query uri.to_s end |