Class: XRB::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/xrb/reference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, query = {}, fragment: nil) ⇒ Reference

Returns a new instance of Reference.



10
11
12
13
14
# File 'lib/xrb/reference.rb', line 10

def initialize(path, query = {}, fragment: nil)
	@path = path.to_s
	@query = query
	@fragment = fragment
end

Instance Attribute Details

#fragmentObject (readonly)

A fragment identifier, the part after the ‘#’



23
24
25
# File 'lib/xrb/reference.rb', line 23

def fragment
  @fragment
end

#pathObject (readonly)

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



17
18
19
# File 'lib/xrb/reference.rb', line 17

def path
  @path
end

#queryObject (readonly)

The query parameters.



20
21
22
# File 'lib/xrb/reference.rb', line 20

def query
  @query
end

Instance Method Details

#append(buffer) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/xrb/reference.rb', line 25

def append(buffer)
	buffer << escape_path(@path)
	
	unless @query.empty?
		buffer << "?" << query_string
	end
	
	if @fragment
		buffer << "#" << escape(@fragment)
	end
	
	return buffer
end

#to_strObject Also known as: to_s



39
40
41
# File 'lib/xrb/reference.rb', line 39

def to_str
	append(String.new)
end