lib/wmap/utils/url_magic.rb
# Construct the absolute URL by comparing a known URL and the relative file path
Construct the absolute URL by comparing a known URL and the relative file path
Construct the absolute URL by comparing a known URL and the relative file path
def create_absolute_url_from_context(potential_base, relative_url)
    puts "Determine the absolute URL from context:\n Known base: #{potential_base}, Relative path: #{relative_url}" if @verbose
		absolute_url = nil
		relative_url.sub!(/^\//,'')
		if potential_base =~ /\/$/
			absolute_url = potential_base+relative_url.strip
		else
			last_index_of_slash = potential_base.rindex('/')
			if potential_base[last_index_of_slash-2, 2] == ':/'
				absolute_url = potential_base+relative_url
			else
				last_index_of_dot = potential_base.rindex('.')
				if last_index_of_dot < last_index_of_slash
					absolute_url = potential_base.strip.chop+relative_url
				else
					absolute_url = potential_base[0, last_index_of_slash+1] + relative_url
				end
			end
		end
		puts "Found absolute URL: #{absolute_url}" if @verbose
		return absolute_url
  rescue => ee
		puts "Exception on method #{__method__}: #{ee}" if @verbose
    return nil
  end
def create_absolute_url_from_context ( potential_base , relative_url ) puts "Determine the absolute URL from context:\n Known base: #{potential_base}, Relative path: #{relative_url}" if @verbose absolute_url = nil relative_url . sub! ( / ^ \/ / , '' ) if potential_base =~ / \/ $ / absolute_url = potential_base + relative_url . strip else last_index_of_slash = potential_base . rindex ( '/' ) if potential_base [ last_index_of_slash - 2 , 2 ] == ':/' absolute_url = potential_base + relative_url else last_index_of_dot = potential_base . rindex ( '.' ) if last_index_of_dot < last_index_of_slash absolute_url = potential_base . strip . chop + relative_url else absolute_url = potential_base [ 0 , last_index_of_slash + 1 ] + relative_url end end end puts "Found absolute URL: #{absolute_url}" if @verbose return absolute_url rescue => ee puts "Exception on method #{__method__}: #{ee}" if @verbose return nil end
Construct the absolute URL by comparing a known URL and the relative file path
Construct the absolute URL by comparing a known URL and the relative file path
# make relative URL naked by removing the beginning '/'
potential_base
<not_specific>
relative_url
<not_specific>