Class: S3Toolkit::UrlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/s3-toolkit/url_parser.rb

Class Method Summary collapse

Class Method Details

.call(s3_url) ⇒ Object

Raises:

  • (URI::InvalidURIError)


5
6
7
8
9
10
11
12
13
# File 'lib/s3-toolkit/url_parser.rb', line 5

def self.call(s3_url)
  raise URI::InvalidURIError, "Unexpected format, expected: s3://<bucket>/<key>" unless s3_url&.start_with?("s3://")

  uri = URI.parse(s3_url)
  bucket = uri.host
  key = uri.path.squeeze("/")[1..] # Strip the leading / and any double //

  [bucket, key]
end