Class: FeedBuilder::UrlBuilder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, html_url, self_url = nil, options = {}) ⇒ UrlBuilder

Returns a new instance of UrlBuilder.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/feedbuilder/url_builder.rb', line 7

def initialize(base_url, html_url, self_url = nil, options = {})
  @base_url = Addressable::URI.parse(base_url)
  @html_url = Addressable::URI.parse(html_url)
  if self_url.present?
    @self_url = Addressable::URI.parse(self_url)
  else
    @self_url = @html_url.dup
    @self_url.path = "#{@self_url.path}.atom"
  end
  @page_param = options[:page_param] || :page
  @per_page_param = options[:per_page_param] || :per_page
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



5
6
7
# File 'lib/feedbuilder/url_builder.rb', line 5

def base_url
  @base_url
end

#html_urlObject (readonly)

Returns the value of attribute html_url.



5
6
7
# File 'lib/feedbuilder/url_builder.rb', line 5

def html_url
  @html_url
end

#self_urlObject (readonly)

Returns the value of attribute self_url.



5
6
7
# File 'lib/feedbuilder/url_builder.rb', line 5

def self_url
  @self_url
end

Instance Method Details

#first_url(per_page) ⇒ Object



20
21
22
23
24
25
# File 'lib/feedbuilder/url_builder.rb', line 20

def first_url(per_page)
  self_url.dup.tap do |copy|
    copy.query_values = hashify_query_values(copy).
      merge(@page_param.to_s => '1', @per_page_param.to_s => per_page.to_s)
  end
end

#last_url(total_pages, per_page) ⇒ Object



41
42
43
44
45
46
# File 'lib/feedbuilder/url_builder.rb', line 41

def last_url(total_pages, per_page)
  self_url.dup.tap do |copy|
    copy.query_values = hashify_query_values(copy).
      merge(@page_param.to_s => total_pages.to_s, @per_page_param.to_s => per_page.to_s)
  end
end

#next_url(current_page, per_page) ⇒ Object



27
28
29
30
31
32
# File 'lib/feedbuilder/url_builder.rb', line 27

def next_url(current_page, per_page)
  self_url.dup.tap do |copy|
    copy.query_values = hashify_query_values(copy).
      merge(@page_param.to_s => (current_page + 1).to_s, @per_page_param.to_s => per_page.to_s)
  end
end

#prev_url(current_page, per_page) ⇒ Object



34
35
36
37
38
39
# File 'lib/feedbuilder/url_builder.rb', line 34

def prev_url(current_page, per_page)
  self_url.dup.tap do |copy|
    copy.query_values = hashify_query_values(copy).
      merge(@page_param.to_s => (current_page - 1).to_s, @per_page_param.to_s => per_page.to_s)
  end
end