Sha256: ec0aa63f3a96718ef40ca00bc7504e867c7caecec76b6fb75c2a17d8355cb7e2

Contents?: true

Size: 847 Bytes

Versions: 3

Compression:

Stored size: 847 Bytes

Contents

gem 'addressable', '~>2.0'
require 'addressable/uri'

module DataObjects
  URI = Struct.new(:scheme, :user, :password, :host, :port, :path, :query, :fragment)

  class URI
    def self.parse(uri)
      return uri if uri.kind_of?(self)
      uri = Addressable::URI::parse(uri) unless uri.kind_of?(Addressable::URI)
      self.new(uri.scheme, uri.user, uri.password, uri.host, uri.port, uri.path, uri.query, uri.fragment)
    end

    def to_s
      string = ""
      string << "#{scheme}://"   if scheme
      if user
        string << "#{user}"
        string << ":#{password}" if password
        string << "@"
      end
      string << "#{host}"        if host
      string << ":#{port}"       if port
      string << path.to_s
      string << "?#{query}"      if query
      string << "##{fragment}"   if fragment
      string
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
data_objects-0.9.7 lib/data_objects/uri.rb
data_objects-0.9.9 lib/data_objects/uri.rb
data_objects-0.9.8 lib/data_objects/uri.rb