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
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 |
# 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
#sld ⇒ Object
#
Attributes = #
#
44 45 46 |
# File 'lib/uniform_resource_identifier/domain.rb', line 44 def sld @sld end |
#tld ⇒ Object
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
36 37 38 |
# File 'lib/uniform_resource_identifier/domain.rb', line 36 def blank? @sld.blank? && @tld.blank? end |
#to_h ⇒ Object
32 33 34 |
# File 'lib/uniform_resource_identifier/domain.rb', line 32 def to_h { :sld => @sld, :tld => @tld } end |
#to_s ⇒ Object
27 28 29 30 |
# File 'lib/uniform_resource_identifier/domain.rb', line 27 def to_s sld = "#{@sld}." unless @sld.nil? "#{sld}#{@tld}" end |