class Domain

A class representing a syntactically valid domain. Essentially, the part after the “@” in an email address. Once constructed, you can be sure that it's valid.

Public Class Methods

new(domain) click to toggle source

Initialize this Domain object. If the domain is invalid, then an {InvalidDomainError} will be raised containing the reason why the domain is invalid.

@param domain [String] the string representation of this domain.

# File lib/common/domain.rb, line 19
def initialize(domain)
  if domain.empty? then
    msg = "domain cannot be empty"
    raise InvalidDomainError.new(msg)
  end

  @domain = domain
end

Public Instance Methods

<=>(other) click to toggle source

Compare two Domain objects for sorting purposes. The comparison is based on their String representations.

@param other [Domain] the Domain object to compare me to.

@return [0,1,-1] a trinary indicator of how self relates to other,

obtained by performing the same comparison on the String
representations of *self* and *other*.
# File lib/common/domain.rb, line 61
def <=>(other)
  return self.to_s() <=> other.to_s()
end
==(other) click to toggle source

Check if this Domain is equal to some other Domain. The comparison is based on their String representations.

@param other [Domain] the Domain object to compare me to.

@return [Boolean] If self and other have equal String

representations, then true is returned. Otherwise, false is
returned.
# File lib/common/domain.rb, line 47
def ==(other)
  return self.to_s() == other.to_s()
end
to_s() click to toggle source

Convert this domain to a String.

@return [String] the string representation of this Domain.

# File lib/common/domain.rb, line 33
def to_s()
  return @domain
end