Class: UniformResourceIdentifier::Authority

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parsable

parse

Constructor Details

#initialize(authority = nil) ⇒ Authority

Returns a new instance of Authority.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/uniform_resource_identifier/authority.rb', line 11

def initialize(authority=nil)
  if authority.respond_to?(:to_str)
    authority = Parser.parse(authority)
    
    port = authority[:port].blank? ? nil : authority[:port].to_i if authority.has_key?(:port)
    
    @user_info = UserInfo.parse(authority[:user_info]) if authority.has_key?(:user_info)
    @host = Host.parse(authority[:host]) if authority.has_key?(:host)
    @port = port
  elsif authority.respond_to?(:to_hash)
    authority = authority.to_hash.symbolize_keys
    
    port = authority[:port].blank? ? nil : authority[:port].to_i if authority.has_key?(:port)
    
    @user_info = UserInfo.parse(authority[:user_info]) if authority.has_key?(:user_info)
    @host = Host.parse(authority[:host]) if authority.has_key?(:host)
    
    @port = port
  else
    raise(TypeError, "authority must either be a String or a Hash") unless authority.nil?
  end
end

Instance Attribute Details

#portObject

Returns the value of attribute port.



72
73
74
# File 'lib/uniform_resource_identifier/authority.rb', line 72

def port
  @port
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/uniform_resource_identifier/authority.rb', line 48

def blank?
  @user_info.blank? && @host.blank? && @port.blank?
end

#domainObject



106
107
108
# File 'lib/uniform_resource_identifier/authority.rb', line 106

def domain
  self.host.domain ||= Domain.new
end

#domain=(domain) ⇒ Object



110
111
112
# File 'lib/uniform_resource_identifier/authority.rb', line 110

def domain=(domain)
  self.host.domain = Domain.parse(domain)
end

#hostObject



64
65
66
# File 'lib/uniform_resource_identifier/authority.rb', line 64

def host
  @host ||= Host.new
end

#host=(host) ⇒ Object



68
69
70
# File 'lib/uniform_resource_identifier/authority.rb', line 68

def host=(host)
  @host = Host.parse(host)
end

#passwordObject



90
91
92
# File 'lib/uniform_resource_identifier/authority.rb', line 90

def password
  self..password
end

#password=(password) ⇒ Object



94
95
96
# File 'lib/uniform_resource_identifier/authority.rb', line 94

def password=(password)
  self..password = password
end

#sldObject



114
115
116
# File 'lib/uniform_resource_identifier/authority.rb', line 114

def sld
  self.host.domain.sld
end

#sld=(sld) ⇒ Object



118
119
120
# File 'lib/uniform_resource_identifier/authority.rb', line 118

def sld=(sld)
  self.host.domain.sld = sld
end

#subdomainObject



98
99
100
# File 'lib/uniform_resource_identifier/authority.rb', line 98

def subdomain
  self.host.subdomain
end

#subdomain=(subdomain) ⇒ Object



102
103
104
# File 'lib/uniform_resource_identifier/authority.rb', line 102

def subdomain=(subdomain)
  self.host.subdomain = subdomain
end

#tldObject



122
123
124
# File 'lib/uniform_resource_identifier/authority.rb', line 122

def tld
  self.host.domain.tld
end

#tld=(tld) ⇒ Object



126
127
128
# File 'lib/uniform_resource_identifier/authority.rb', line 126

def tld=(tld)
  self.host.domain.tld = tld
end

#to_hObject



40
41
42
43
44
45
46
# File 'lib/uniform_resource_identifier/authority.rb', line 40

def to_h
  {
    :user_info => .nil? ? nil : @user_info.to_h,
    :host      => host.nil? ? nil : @host.to_h,
    :port      => @port
  }
end

#to_sObject



34
35
36
37
38
# File 'lib/uniform_resource_identifier/authority.rb', line 34

def to_s
   = "#{@user_info}@" unless @user_info.blank?
  port = ":#{@port}" unless @port.blank?
  "#{}#{@host}#{port}"
end

#user_infoObject

#

Attributes = #

#


56
57
58
# File 'lib/uniform_resource_identifier/authority.rb', line 56

def 
  @user_info ||= UserInfo.new
end

#user_info=(user_info) ⇒ Object



60
61
62
# File 'lib/uniform_resource_identifier/authority.rb', line 60

def user_info=()
  @user_info = UserInfo.parse()
end

#usernameObject

#

Delegates = #

#


82
83
84
# File 'lib/uniform_resource_identifier/authority.rb', line 82

def username
  self..username
end

#username=(username) ⇒ Object



86
87
88
# File 'lib/uniform_resource_identifier/authority.rb', line 86

def username=(username)
  self..username = username
end

#valid_public_suffix?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/uniform_resource_identifier/authority.rb', line 130

def valid_public_suffix?
  self.host.domain.valid_public_suffix?
end