Class: Trenni::URI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of URI.



23
24
25
26
27
28
# File 'lib/trenni/uri.rb', line 23

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 ‘#’



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

def fragment
  @fragment
end

#parametersObject (readonly)

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



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

def parameters
  @parameters
end

#pathObject (readonly)

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



31
32
33
# File 'lib/trenni/uri.rb', line 31

def path
  @path
end

#query_stringObject (readonly)

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



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

def query_string
  @query_string
end

Instance Method Details

#append(buffer) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/trenni/uri.rb', line 42

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



58
59
60
# File 'lib/trenni/uri.rb', line 58

def to_str
	append(String.new)
end