Class: UniformResourceIdentifier::Authority
- Inherits:
-
Object
- Object
- UniformResourceIdentifier::Authority
- Extended by:
- Parsable
- Defined in:
- lib/uniform_resource_identifier/authority.rb
Instance Attribute Summary collapse
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #domain ⇒ Object
- #domain=(domain) ⇒ Object
- #host ⇒ Object
- #host=(host) ⇒ Object
-
#initialize(authority = nil) ⇒ Authority
constructor
A new instance of Authority.
- #password ⇒ Object
- #password=(password) ⇒ Object
- #sld ⇒ Object
- #sld=(sld) ⇒ Object
- #subdomain ⇒ Object
- #subdomain=(subdomain) ⇒ Object
- #tld ⇒ Object
- #tld=(tld) ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
-
#user_info ⇒ Object
# = Attributes = # ======================================================================= #.
- #user_info=(user_info) ⇒ Object
-
#username ⇒ Object
# = Delegates = # ======================================================================= #.
- #username=(username) ⇒ Object
- #valid_public_suffix? ⇒ Boolean
Methods included from Parsable
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(=nil) if .respond_to?(:to_str) = Parser.parse() port = [:port].blank? ? nil : [:port].to_i if .has_key?(:port) @user_info = UserInfo.parse([:user_info]) if .has_key?(:user_info) @host = Host.parse([:host]) if .has_key?(:host) @port = port elsif .respond_to?(:to_hash) = .to_hash.symbolize_keys port = [:port].blank? ? nil : [:port].to_i if .has_key?(:port) @user_info = UserInfo.parse([:user_info]) if .has_key?(:user_info) @host = Host.parse([:host]) if .has_key?(:host) @port = port else raise(TypeError, "authority must either be a String or a Hash") unless .nil? end end |
Instance Attribute Details
#port ⇒ Object
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
48 49 50 |
# File 'lib/uniform_resource_identifier/authority.rb', line 48 def blank? @user_info.blank? && @host.blank? && @port.blank? end |
#domain ⇒ Object
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 |
#host ⇒ Object
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 |
#password ⇒ Object
90 91 92 |
# File 'lib/uniform_resource_identifier/authority.rb', line 90 def password self.user_info.password end |
#password=(password) ⇒ Object
94 95 96 |
# File 'lib/uniform_resource_identifier/authority.rb', line 94 def password=(password) self.user_info.password = password end |
#sld ⇒ Object
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 |
#subdomain ⇒ Object
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 |
#tld ⇒ Object
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_h ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/uniform_resource_identifier/authority.rb', line 40 def to_h { :user_info => user_info.nil? ? nil : @user_info.to_h, :host => host.nil? ? nil : @host.to_h, :port => @port } end |
#to_s ⇒ Object
34 35 36 37 38 |
# File 'lib/uniform_resource_identifier/authority.rb', line 34 def to_s user_info = "#{@user_info}@" unless @user_info.blank? port = ":#{@port}" unless @port.blank? "#{user_info}#{@host}#{port}" end |
#user_info ⇒ Object
#
Attributes = #
#
56 57 58 |
# File 'lib/uniform_resource_identifier/authority.rb', line 56 def user_info @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) @user_info = UserInfo.parse(user_info) end |
#username ⇒ Object
#
Delegates = #
#
82 83 84 |
# File 'lib/uniform_resource_identifier/authority.rb', line 82 def username self.user_info.username end |
#username=(username) ⇒ Object
86 87 88 |
# File 'lib/uniform_resource_identifier/authority.rb', line 86 def username=(username) self.user_info.username = username end |
#valid_public_suffix? ⇒ Boolean
130 131 132 |
# File 'lib/uniform_resource_identifier/authority.rb', line 130 def valid_public_suffix? self.host.domain.valid_public_suffix? end |