Class: Hootenanny::URI

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/hootenanny/uri.rb,
lib/hootenanny/errors.rb

Defined Under Namespace

Classes: InvalidError, InvalidSchemeError

Constant Summary collapse

VALID_SCHEMES =
['http', 'https']

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(uriable) ⇒ Object

Private: Parses a String into a URI in conformance to the the PubSubHubbub spec. Only HTTP and HTTPS URIs are allowed.

Returns a Ruby URI Raises a Hootenanny::URI::InvalidSchemeError if something other than an HTTP

or HTTPS URI is parsed

Raises a Hootenanny::URI::InvalidError if the URI cannot be parsed



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hootenanny/uri.rb', line 19

def self.parse(uriable)
  uri = if uriable.is_a? self
          uriable
        else
          ::URI.parse(uriable)
        end

  uri.fragment = nil

  if !VALID_SCHEMES.include?(uri.scheme)
    raise Hootenanny::URI::InvalidSchemeError
  end

  self.new(uri)
rescue ::URI::InvalidURIError => e
  raise Hootenanny::URI::InvalidError.wrap(e)
end

Instance Method Details

#==(comparee) ⇒ Object



41
42
43
# File 'lib/hootenanny/uri.rb', line 41

def ==(comparee)
  self.to_s == comparee.to_s
end

#eql?(comparee) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/hootenanny/uri.rb', line 45

def eql?(comparee)
  self == comparee
end

#hashObject



37
38
39
# File 'lib/hootenanny/uri.rb', line 37

def hash
  self.to_s.hash
end

#to_digestObject



49
50
51
# File 'lib/hootenanny/uri.rb', line 49

def to_digest
  @digest ||= Digest::SHA256.hexdigest(self.to_s)[0..16]
end