Class: UniformResourceIdentifier::Domain

Inherits:
Object
  • Object
show all
Extended by:
Parsable
Defined in:
lib/uniform_resource_identifier/domain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parsable

parse

Constructor Details

#initialize(domain = nil) ⇒ Domain

Returns a new instance of Domain.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/uniform_resource_identifier/domain.rb', line 9

def initialize(domain=nil)
  if domain.respond_to?(:to_str) 
    begin
      pss = PublicSuffixService.parse(domain)
      
      @sld, @tld = pss.sld, pss.tld
    rescue PublicSuffixService::DomainInvalid
      # We couldn't parse your tld (public suffix) =(
      @tld = domain
    end
  elsif domain.respond_to?(:to_hash)
    domain.to_hash.symbolize_keys
    @sld, @tld = domain.values_at(:sld, :tld)
  else
    raise(TypeError, "domain must either be a String or a Hash") unless domain.nil?
  end
end

Instance Attribute Details

#sldObject

#

Attributes = #

#


44
45
46
# File 'lib/uniform_resource_identifier/domain.rb', line 44

def sld
  @sld
end

#tldObject

Returns the value of attribute tld.



45
46
47
# File 'lib/uniform_resource_identifier/domain.rb', line 45

def tld
  @tld
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/uniform_resource_identifier/domain.rb', line 36

def blank?
  @sld.blank? && @tld.blank?
end

#to_hObject



32
33
34
# File 'lib/uniform_resource_identifier/domain.rb', line 32

def to_h
  { :sld => @sld, :tld => @tld }
end

#to_sObject



27
28
29
30
# File 'lib/uniform_resource_identifier/domain.rb', line 27

def to_s
  sld = "#{@sld}." unless @sld.nil?
  "#{sld}#{@tld}"
end