Class: Flare::Url
- Inherits:
-
Object
- Object
- Flare::Url
- Defined in:
- lib/flare/url.rb
Class Method Summary collapse
-
.host(string) ⇒ Object
Attempts to parse a string to get the ‘host` value from it.
-
.is_valid?(url) ⇒ Boolean
Returns if a url is valid after being parsed.
-
.parse_host(string) ⇒ Object
Uses PublicSuffix to lookup validated domain names.
-
.parsed(url) ⇒ Object
Base parse method which handles invalid uris.
-
.scheme(url) ⇒ Object
Returns the scheme (http, https, ftp) for a url.
Class Method Details
.host(string) ⇒ Object
Attempts to parse a string to get the ‘host` value from it. Typically this value is in the form of `google.com` or `inbox.google.com` with subdomains.
32 33 34 |
# File 'lib/flare/url.rb', line 32 def self.host(string) parsed(string)&.host end |
.is_valid?(url) ⇒ Boolean
Returns if a url is valid after being parsed.
23 24 25 |
# File 'lib/flare/url.rb', line 23 def self.is_valid?(url) %w(http https).include?(scheme(url)) end |
.parse_host(string) ⇒ Object
Uses PublicSuffix to lookup validated domain names.
16 17 18 |
# File 'lib/flare/url.rb', line 16 def self.parse_host(string) PublicSuffix.parse(host(string)) end |
.parsed(url) ⇒ Object
Base parse method which handles invalid uris.
7 8 9 10 11 |
# File 'lib/flare/url.rb', line 7 def self.parsed(url) Addressable::URI.heuristic_parse(url) rescue Addressable::URI::InvalidURIError => error nil end |
.scheme(url) ⇒ Object
Returns the scheme (http, https, ftp) for a url.
39 40 41 |
# File 'lib/flare/url.rb', line 39 def self.scheme(url) parsed(url)&.scheme end |