Class: Trenni::Reference

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Reference.



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

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



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

def fragment
  @fragment
end

#pathObject (readonly)

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



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

def path
  @path
end

#queryObject (readonly)

The query parameters.



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

def query
  @query
end

Instance Method Details

#append(buffer) ⇒ Object



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

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



56
57
58
# File 'lib/trenni/reference.rb', line 56

def to_str
	append(String.new)
end