Class: Http2::UrlBuilder
- Inherits:
-
Object
- Object
- Http2::UrlBuilder
- Defined in:
- lib/http2/url_builder.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
-
#port ⇒ Object
Returns the value of attribute port.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
Instance Method Summary collapse
- #build ⇒ Object
- #build_params ⇒ Object
- #build_path_and_params ⇒ Object
-
#initialize ⇒ UrlBuilder
constructor
A new instance of UrlBuilder.
- #params? ⇒ Boolean
Constructor Details
#initialize ⇒ UrlBuilder
Returns a new instance of UrlBuilder.
4 5 6 |
# File 'lib/http2/url_builder.rb', line 4 def initialize @params = {} end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
2 3 4 |
# File 'lib/http2/url_builder.rb', line 2 def host @host end |
#params ⇒ Object
Returns the value of attribute params.
2 3 4 |
# File 'lib/http2/url_builder.rb', line 2 def params @params end |
#path ⇒ Object
Returns the value of attribute path.
2 3 4 |
# File 'lib/http2/url_builder.rb', line 2 def path @path end |
#port ⇒ Object
Returns the value of attribute port.
2 3 4 |
# File 'lib/http2/url_builder.rb', line 2 def port @port end |
#protocol ⇒ Object
Returns the value of attribute protocol.
2 3 4 |
# File 'lib/http2/url_builder.rb', line 2 def protocol @protocol end |
Instance Method Details
#build ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/http2/url_builder.rb', line 41 def build url = "" url << "#{protocol}://" if protocol if host url << host url << ":#{port}/" if port end url << build_path_and_params url end |
#build_params ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/http2/url_builder.rb', line 8 def build_params url_params = "" unless params.empty? first = true params.each do |key, val| if first first = false else url_params << "&" end url_params << Http2::Utils.urlenc(key) url_params << "=" url_params << Http2::Utils.urlenc(val) end end url_params end |
#build_path_and_params ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/http2/url_builder.rb', line 30 def build_path_and_params url = path.to_s if params? url << "?" url << build_params end url end |
#params? ⇒ Boolean
55 56 57 |
# File 'lib/http2/url_builder.rb', line 55 def params? @params.any? end |