]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/domain.rb
1 require 'common/errors'
3 # A class representing a syntactically valid domain. Essentially, the
4 # part after the "@" in an email address. Once constructed, you can be
5 # sure that it's valid.
9 # @domain contains the String representation of this domain.
13 # Initialize this Domain object. If the domain is invalid, then an
14 # {InvalidDomainError} will be raised containing the reason
15 # why the domain is invalid.
17 # @param domain [String] the string representation of this domain.
19 def initialize(domain
)
21 msg
= "domain cannot be empty"
22 raise InvalidDomainError
.new(msg
)
29 # Convert this domain to a String.
31 # @return [String] the string representation of this Domain.
38 # Check if this Domain is equal to some other Domain. The comparison
39 # is based on their String representations.
41 # @param other [Domain] the Domain object to compare me to.
43 # @return [Boolean] If *self* and *other* have equal String
44 # representations, then true is returned. Otherwise, false is
48 return self.to_s() == other
.to_s()
52 # Compare two Domain objects for sorting purposes. The comparison
53 # is based on their String representations.
55 # @param other [Domain] the Domain object to compare me to.
57 # @return [0,1,-1] a trinary indicator of how *self* relates to *other*,
58 # obtained by performing the same comparison on the String
59 # representations of *self* and *other*.
62 return self.to_s() <=> other
.to_s()