class TrueURL::Context
Attributes
attributes[R]
options[R]
original_url[R]
working_url[R]
Public Class Methods
new(original_url, options)
click to toggle source
# File lib/true_url/context.rb, line 7 def initialize(original_url, options) @original_url = parse(original_url) @options = options @finalized = false @attributes = {} set_working_url(original_url) end
Public Instance Methods
finalize()
click to toggle source
# File lib/true_url/context.rb, line 27 def finalize @finalized = true end
finalized?()
click to toggle source
# File lib/true_url/context.rb, line 31 def finalized? @finalized end
set_working_url(url, base_url = nil)
click to toggle source
# File lib/true_url/context.rb, line 16 def set_working_url(url, base_url = nil) @working_url = base_url.nil? ? parse(url) : parse(base_url).join(parse(url)) # If the URL has no scheme, then we assume HTTP if @working_url.scheme.nil? @working_url = url.to_s.start_with?('//') ? parse("http:#{url}") : parse("http://#{url}") end @working_url.normalize end
Private Instance Methods
parse(url)
click to toggle source
# File lib/true_url/context.rb, line 37 def parse(url) url.is_a?(Addressable::URI) ? url : Addressable::URI.parse(url) end