Class: Trenni::URI

Inherits:
Object
  • Object
show all
Defined in:
lib/trenni/uri.rb

Overview

This class is superceeded by ‘Trenni::Reference`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, query_string, fragment, parameters) ⇒ URI

Returns a new instance of URI.



26
27
28
29
30
31
# File 'lib/trenni/uri.rb', line 26

def initialize(path, query_string, fragment, parameters)
	@path = path
	@query_string = query_string
	@fragment = fragment
	@parameters = parameters
end

Instance Attribute Details

#fragmentObject (readonly)

A fragment identifier, the part after the ‘#’



40
41
42
# File 'lib/trenni/uri.rb', line 40

def fragment
  @fragment
end

#parametersObject (readonly)

User supplied parameters that will be appended to the query part.



43
44
45
# File 'lib/trenni/uri.rb', line 43

def parameters
  @parameters
end

#pathObject (readonly)

The path component of the URI, e.g. /foo/bar/index.html



34
35
36
# File 'lib/trenni/uri.rb', line 34

def path
  @path
end

#query_stringObject (readonly)

The un-parsed query string of the URI, e.g. ‘x=10&y=20’



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

def query_string
  @query_string
end

Instance Method Details

#append(buffer) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/trenni/uri.rb', line 45

def append(buffer)
	if @query_string
		buffer << escape_path(@path) << '?' << query_string
		buffer << '&' << query_parameters if @parameters
	else
		buffer << escape_path(@path)
		buffer << '?' << query_parameters if @parameters
	end
	
	if @fragment
		buffer << '#' << escape(@fragment)
	end
	
	return buffer
end

#to_strObject Also known as: to_s



61
62
63
# File 'lib/trenni/uri.rb', line 61

def to_str
	append(String.new)
end