Class: SimpleUrl::Url

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, query_string_class) ⇒ Url



10
11
12
13
14
15
# File 'lib/simple_url.rb', line 10

def initialize(url, query_string_class)
  @url = URI(url)
  @path = Pathname.new(@url.path)
  @query_string_class = query_string_class
  @query = query_string_class.from_string(@url.query)
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/simple_url.rb', line 7

def path
  @path
end

#queryObject

Returns the value of attribute query.



7
8
9
# File 'lib/simple_url.rb', line 7

def query
  @query
end

#query_string_classObject (readonly)

Returns the value of attribute query_string_class.



8
9
10
# File 'lib/simple_url.rb', line 8

def query_string_class
  @query_string_class
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/simple_url.rb', line 7

def url
  @url
end

Instance Method Details

#append_path(path) ⇒ Object



17
18
19
# File 'lib/simple_url.rb', line 17

def append_path(path)
  @path = @path.join(path)
end

#normalize_pathObject



21
22
23
# File 'lib/simple_url.rb', line 21

def normalize_path
  @path = @path.cleanpath
end

#to_sObject



25
26
27
28
29
30
# File 'lib/simple_url.rb', line 25

def to_s
  q = @query.to_s
  @url.query = q unless q.empty?
  @url.path = @path.to_s
  @url.to_s
end