Sha256: f684f0bd452f60fb3a41d7443f58b002a820cd0fa6463a913ca2c506f31097a5

Contents?: true

Size: 877 Bytes

Versions: 4

Compression:

Stored size: 877 Bytes

Contents

require 'uri'

module BerkeleyLibrary
  module Util
    module URIs
      module Validator
        class << self

          # Returns the specified URL as a URI.
          # @param url [String, URI] the URL.
          # @return [URI] the URI.
          # @raise [URI::InvalidURIError] if `url` cannot be parsed as a URI.
          def uri_or_nil(url)
            return unless url

            # noinspection RubyMismatchedReturnType
            url.is_a?(URI) ? url : URI.parse(url.to_s)
          end

          # Returns the specified URL as a string.
          # @param url [String, URI] the URL.
          # @return [String] the URL.
          # @raise [URI::InvalidURIError] if `url` cannot be parsed as a URI.
          def url_str_or_nil(url)
            uri = Validator.uri_or_nil(url)
            uri.to_s if uri
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
berkeley_library-util-0.1.3 lib/berkeley_library/util/uris/validator.rb
berkeley_library-util-0.1.2 lib/berkeley_library/util/uris/validator.rb
berkeley_library-util-0.1.1 lib/berkeley_library/util/uris/validator.rb
berkeley_library-util-0.1.0 lib/berkeley_library/util/uris/validator.rb