Sha256: 8a51d976ffc6372d14a86cbf0ec3c462a7cad22dc86570e9e56978457b43c7fd

Contents?: true

Size: 718 Bytes

Versions: 4

Compression:

Stored size: 718 Bytes

Contents

module Merritt
  # Miscellaneous utility methods
  module Util
    class << self
      # Ensures that the specified argument is a URI.
      # @param url [String, URI] The argument. If the argument is already
      #   a URI, it is returned unchanged; otherwise, the argument's string
      #   form (as returned by +`to_s`+) is parsed as a URI.
      # @return [nil, URI] +`nil`+ if +`url`+ is nil, otherwise the URI.
      # @raise [URI::InvalidURIError] if `url` is a string that is not a valid URI
      def to_uri(url)
        return nil unless url
        return url if url.is_a? URI
        stripped = url.respond_to?(:strip) ? url.strip : url.to_s.strip
        URI.parse(stripped)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
merritt-manifest-0.1.3 lib/merritt/util.rb
merritt-manifest-0.1.2 lib/merritt/util.rb
merritt-manifest-0.1.1 lib/merritt/util.rb
merritt-manifest-0.1.0 lib/merritt/util.rb