Class: URI::Builder::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/uri/builder.rb

Constant Summary collapse

File =
::File

Instance Method Summary collapse

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

#parentObject



22
23
24
# File 'lib/uri/builder.rb', line 22

def parent
  self.class.new(*@segments[0...-1])
end

#to_sObject



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