Module: LazyDomain

Extended by:
AutoHTTP
Defined in:
lib/lazy_domain.rb,
lib/lazy_domain/version.rb

Overview

Make parsing PublicSuffix domains easier.

Constant Summary collapse

VERSION =
'0.0.2'

Constants included from AutoHTTP

AutoHTTP::BADURL_REGEX, AutoHTTP::TP_REGEX

Class Method Summary collapse

Methods included from AutoHTTP

autohttp, bad_protocol?, hastp?, strip_bad

Class Method Details

.parse(str) ⇒ Object

Example: domain = LazyDomain.parse(google.com)

domain.tld

> ‘com’

domain.sld

> ‘google’

domain.trd

> nil

domain.domain

> ‘google.com’

domain.subdomain # => nil



74
75
76
# File 'lib/lazy_domain.rb', line 74

def parse(str)
  PublicSuffix.parse(uri_host(str))
end

.uri_host(str) ⇒ Object

Because URI cannot parse anything without a transfer protocol, this automagically adds one if not present.

This method always PublicSuffix to parse varying urls that may or may not have a protocol.



50
51
52
# File 'lib/lazy_domain.rb', line 50

def uri_host(str)
  URI.parse(autohttp(str)).host
end

.valid?(str) ⇒ Boolean

LazyDomain.valid?(“x.yz”)

> false

Returns:

  • (Boolean)


87
88
89
# File 'lib/lazy_domain.rb', line 87

def valid?(str)
  PublicSuffix.valid?(uri_host(str))
end