Class: URI::Builder::Path
- Inherits:
-
Object
- Object
- URI::Builder::Path
- Defined in:
- lib/uri/builder.rb
Constant Summary collapse
- File =
::File
Instance Method Summary collapse
-
#initialize(*segments) ⇒ Path
constructor
A new instance of Path.
- #join(*segments) ⇒ Object
- #parent ⇒ Object
- #to_s ⇒ Object
- #trailing_slash(value = true) ⇒ Object
Constructor Details
#initialize(*segments) ⇒ Path
Returns a new instance of Path.
13 14 15 16 |
# File 'lib/uri/builder.rb', line 13 def initialize(*segments) @trailing_slash = segments.last.to_s.end_with?("/") @segments = segments.compact.flat_map { _1.to_s.split("/") } end |
Instance Method Details
#join(*segments) ⇒ Object
18 19 20 |
# File 'lib/uri/builder.rb', line 18 def join(*segments) self.class.new(*@segments, *segments) end |
#parent ⇒ Object
22 23 24 |
# File 'lib/uri/builder.rb', line 22 def parent self.class.new(*@segments[0...-1]) end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/uri/builder.rb', line 26 def to_s File.join("/", *@segments.map(&:to_s).tap { _1.append "/" if @trailing_slash }) end |
#trailing_slash(value = true) ⇒ Object
30 31 32 33 |
# File 'lib/uri/builder.rb', line 30 def trailing_slash(value = true) @trailing_slash = value self end |