Module: Tootsie::S3Utilities

Defined in:
lib/tootsie/s3_utilities.rb

Class Method Summary collapse

Class Method Details

.parse_uri(url) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tootsie/s3_utilities.rb', line 6

def parse_uri(url)
  if url =~ /^s3:([^\/]+)\/+(.+?)(?:\?(.*))?$/
    output = {}.with_indifferent_access
    output[:bucket], output[:key], option_string = $1, $2, $3
    unless option_string.blank?
      option_string.split('&').map { |pair| pair.scan(/^(.*?)=(.*)$/)[0] }.each do |k, v|
        output[k] = v.to_sym
      end
    end
    output
  else
    raise ArgumentError, "Not an S3 URL"
  end
end