Class: Xing::Serializers::PagedList

Inherits:
List
  • Object
show all
Defined in:
lib/xing/serializers/paged_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from List

#as_json_without_wrap, #item_serializer_class, #item_serializer_options, #self_link, #template_link

Methods inherited from Base

#as_json_with_wrap, #root, #routes

Constructor Details

#initialize(list, page_num, total_pages, options = {}) ⇒ PagedList

Returns a new instance of PagedList.



5
6
7
8
9
10
# File 'lib/xing/serializers/paged_list.rb', line 5

def initialize(list, page_num, total_pages, options = {})
  @page_num = page_num.to_i
  @total_pages = total_pages

  super(list, options)
end

Instance Attribute Details

#page_numObject (readonly)

Returns the value of attribute page_num.



12
13
14
# File 'lib/xing/serializers/paged_list.rb', line 12

def page_num
  @page_num
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



12
13
14
# File 'lib/xing/serializers/paged_list.rb', line 12

def total_pages
  @total_pages
end

Instance Method Details



27
28
29
30
31
32
33
# File 'lib/xing/serializers/paged_list.rb', line 27

def links
  {
    :self => self_link,
    :next => next_link,
    :previous => previous_link
  }
end


19
20
21
# File 'lib/xing/serializers/paged_list.rb', line 19

def next_link
  page_link({page: page_num + 1}) unless page_num == total_pages
end

Raises:

  • (NotImplementedError)


14
15
16
17
# File 'lib/xing/serializers/paged_list.rb', line 14

def page_link(options)
  raise NotImplementedError,
    "subclasses of Xing::Serializers::PagesData must override page_link to return the URL of a page based on a :page => Integer() hash"
end


23
24
25
# File 'lib/xing/serializers/paged_list.rb', line 23

def previous_link
  page_link({page: page_num - 1}) unless page_num == 1
end