Class: Build::URI::Absolute

Inherits:
Struct
  • Object
show all
Includes:
Base
Defined in:
lib/build/uri/absolute.rb

Constant Summary collapse

PARSER =

A subset of RFC2396 specifically relevant to path based URIs. We are not interested in generic URIs such as mailto.

%r{\A
	((?<scheme>[^:\/?\#]+):)
	(\/\/
		((?<userinfo>[^\/?\#]+)@)?
		(?<host>[^\/?\#]*)
	)
	(?<path>[^?\#]*)
	(\?(?<query>[^\#]*))?
	(\#(?<fragment>.*))?
\z}x.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#+, #basename, #dirname, #merge

Instance Attribute Details

#fragmentObject

Returns the value of attribute fragment

Returns:

  • (Object)

    the current value of fragment



25
26
27
# File 'lib/build/uri/absolute.rb', line 25

def fragment
  @fragment
end

#hostObject

Returns the value of attribute host

Returns:

  • (Object)

    the current value of host



25
26
27
# File 'lib/build/uri/absolute.rb', line 25

def host
  @host
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



25
26
27
# File 'lib/build/uri/absolute.rb', line 25

def path
  @path
end

#queryObject

Returns the value of attribute query

Returns:

  • (Object)

    the current value of query



25
26
27
# File 'lib/build/uri/absolute.rb', line 25

def query
  @query
end

#schemeObject

Returns the value of attribute scheme

Returns:

  • (Object)

    the current value of scheme



25
26
27
# File 'lib/build/uri/absolute.rb', line 25

def scheme
  @scheme
end

#userinfoObject

Returns the value of attribute userinfo

Returns:

  • (Object)

    the current value of userinfo



25
26
27
# File 'lib/build/uri/absolute.rb', line 25

def userinfo
  @userinfo
end

Class Method Details

.parse(string) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/build/uri/absolute.rb', line 80

def self.parse(string)
	if match = PARSER.match(string)
		self.new(
			match[:scheme], match[:userinfo], match[:host], match[:path], match[:query], match[:fragment]
		).freeze
	end
end

Instance Method Details

#absolute?Boolean

Returns:

  • (Boolean)


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

def absolute?
	true
end

#local?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/build/uri/absolute.rb', line 44

def local?
	false
end

#to_sObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/build/uri/absolute.rb', line 48

def to_s
	buffer = String.new
	
	if scheme
		buffer << scheme << ':'
	end
	
	if host
		buffer << '//'
		
		if userinfo
			buffer << userinfo << '@'
		end
		
		buffer << host
	end
	
	if path
		buffer << path
	end
	
	if query
		buffer << '?' << query
	end
	
	if fragment
		buffer << '#' << fragment
	end
	
	return buffer
end