Class: TrueURL::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/true_url/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_url, options) ⇒ Context

Returns a new instance of Context.


7
8
9
10
11
12
13
14
# 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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.


5
6
7
# File 'lib/true_url/context.rb', line 5

def attributes
  @attributes
end

#optionsObject (readonly)

Returns the value of attribute options.


5
6
7
# File 'lib/true_url/context.rb', line 5

def options
  @options
end

#original_urlObject (readonly)

Returns the value of attribute original_url.


5
6
7
# File 'lib/true_url/context.rb', line 5

def original_url
  @original_url
end

#working_urlObject (readonly)

Returns the value of attribute working_url.


5
6
7
# File 'lib/true_url/context.rb', line 5

def working_url
  @working_url
end

Instance Method Details

#finalizeObject


27
28
29
# File 'lib/true_url/context.rb', line 27

def finalize
  @finalized = true
end

#finalized?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/true_url/context.rb', line 31

def finalized?
  @finalized
end

#set_working_url(url, base_url = nil) ⇒ Object


16
17
18
19
20
21
22
23
24
25
# 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