Class: UrlValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/url_validator.rb

Overview

Class with methods related to validating URLs.

Class Method Summary collapse

Class Method Details

.valid_entry_url?(url) ⇒ Boolean

Validate if a URL is a valid URL for an entry (either for the entry link, or for any link in the content, e.g. images).

A URL is a valid entry URL if it is an http or https URL, or a protocol-relative URL.

Receives an URL string as argument. Returns a boolean: true if the URL is valid for an entry, false otherwise.

Returns:

  • (Boolean)

14
15
16
17
18
19
20
21
22
# File 'lib/url_validator.rb', line 14

def self.valid_entry_url?(url)
  if url =~ URI::regexp(%w{http https})
    return true
  elsif url =~ /\A\/\//
    return true
  else
    return false
  end
end