Module: Twingly::URL::Normalizer
- Defined in:
- lib/twingly/url/normalizer.rb
Class Method Summary collapse
- .extract_urls(potential_urls) ⇒ Object
- .normalize(potential_urls) ⇒ Object
- .normalize_url(potential_url) ⇒ Object
Class Method Details
.extract_urls(potential_urls) ⇒ Object
14 15 16 |
# File 'lib/twingly/url/normalizer.rb', line 14 def extract_urls(potential_urls) Array(potential_urls).map(&:split).flatten end |
.normalize(potential_urls) ⇒ Object
8 9 10 11 12 |
# File 'lib/twingly/url/normalizer.rb', line 8 def normalize(potential_urls) extract_urls(potential_urls).map do |potential_url| normalize_url(potential_url) end.compact end |
.normalize_url(potential_url) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/twingly/url/normalizer.rb', line 18 def normalize_url(potential_url) result = Twingly::URL.parse(potential_url) return nil unless result.valid? unless result.domain.subdomain? result.url.host = "www.#{result.domain}" end if result.url.path.empty? result.url.path = "/" end result.url.to_s.downcase end |