Class: DataObjects::URI

Inherits:
Struct show all
Defined in:
lib/mack-data_mapper/dm_patches/uri.rb,
lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb,
lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

json_create, #to_json

Instance Attribute Details

#fragmentObject

Returns the value of attribute fragment

Returns:

  • (Object)

    the current value of fragment



5
6
7
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb', line 5

def fragment
  @fragment
end

#hostObject

Returns the value of attribute host

Returns:

  • (Object)

    the current value of host



5
6
7
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb', line 5

def host
  @host
end

#passwordObject

Returns the value of attribute password

Returns:

  • (Object)

    the current value of password



5
6
7
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb', line 5

def password
  @password
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



5
6
7
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb', line 5

def path
  @path
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



5
6
7
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb', line 5

def port
  @port
end

#queryObject

Returns the value of attribute query

Returns:

  • (Object)

    the current value of query



5
6
7
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb', line 5

def query
  @query
end

#schemeObject

Returns the value of attribute scheme

Returns:

  • (Object)

    the current value of scheme



5
6
7
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb', line 5

def scheme
  @scheme
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



5
6
7
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb', line 5

def user
  @user
end

Class Method Details

.parse(uri) ⇒ Object



8
9
10
11
12
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb', line 8

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_values, uri.fragment)
end

Instance Method Details

#basenameObject



4
5
6
# File 'lib/mack-data_mapper/dm_patches/uri.rb', line 4

def basename
  self.path[1..self.path.length]
end

#to_sObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb', line 14

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
  if query
    string << "?" << query.map do |key, value|
      "#{key}=#{value}"
    end.join("&")
  end
  string << "##{fragment}"   if fragment
  string
end