Class: UniformResourceIdentifier::Domain
- Inherits:
-
Object
- Object
- UniformResourceIdentifier::Domain
- Extended by:
- Parsable
- Defined in:
- lib/uniform_resource_identifier/domain.rb
Instance Attribute Summary collapse
-
#sld ⇒ Object
# = Attributes = # ======================================================================= #.
-
#tld ⇒ Object
Returns the value of attribute tld.
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#initialize(domain = nil) ⇒ Domain
constructor
A new instance of Domain.
- #to_h ⇒ Object
- #to_s ⇒ Object
- #valid_public_suffix? ⇒ Boolean
Methods included from Parsable
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 26 27 28 |
# File 'lib/uniform_resource_identifier/domain.rb', line 9 def initialize(domain=nil) if domain.respond_to?(:to_str) begin pss = PublicSuffix.parse(domain) @sld, @tld = pss.sld, pss.tld @valid_public_suffix = true rescue PublicSuffix::DomainInvalid # We couldn't parse your tld (public suffix) =( @tld = domain @valid_public_suffix = false end elsif domain.respond_to?(:to_hash) domain.to_hash.symbolize_keys @sld, @tld = domain.values_at(:sld, :tld) @valid_public_suffix = domain[:valid] else raise(TypeError, "domain must either be a String or a Hash") unless domain.nil? end end |
Instance Attribute Details
#sld ⇒ Object
#
Attributes = #
#
47 48 49 |
# File 'lib/uniform_resource_identifier/domain.rb', line 47 def sld @sld end |
#tld ⇒ Object
Returns the value of attribute tld.
48 49 50 |
# File 'lib/uniform_resource_identifier/domain.rb', line 48 def tld @tld end |
Instance Method Details
#blank? ⇒ Boolean
39 40 41 |
# File 'lib/uniform_resource_identifier/domain.rb', line 39 def blank? @sld.blank? && @tld.blank? end |
#to_h ⇒ Object
35 36 37 |
# File 'lib/uniform_resource_identifier/domain.rb', line 35 def to_h { :sld => @sld, :tld => @tld } end |
#to_s ⇒ Object
30 31 32 33 |
# File 'lib/uniform_resource_identifier/domain.rb', line 30 def to_s sld = "#{@sld}." unless @sld.nil? "#{sld}#{@tld}" end |
#valid_public_suffix? ⇒ Boolean
50 51 52 |
# File 'lib/uniform_resource_identifier/domain.rb', line 50 def valid_public_suffix? @valid_public_suffix end |