Class: Jikanrb::Pagination::PaginationInfo

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

Overview

Represents pagination information from an API response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ PaginationInfo

Returns a new instance of PaginationInfo.

Parameters:

  • response (Hash)

    API response with pagination data



24
25
26
27
28
29
30
# File 'lib/jikanrb/pagination.rb', line 24

def initialize(response)
  @pagination = response['pagination'] || {}
  @current_page = @pagination['current_page'] || 1
  @last_visible_page = @pagination['last_visible_page'] || 1
  @has_next_page = @pagination['has_next_page'] || false
  @items = @pagination['items'] || {}
end

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



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

def current_page
  @current_page
end

#has_next_pageObject (readonly)

Returns the value of attribute has_next_page.



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

def has_next_page
  @has_next_page
end

#itemsObject (readonly)

Returns the value of attribute items.



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

def items
  @items
end

#last_visible_pageObject (readonly)

Returns the value of attribute last_visible_page.



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

def last_visible_page
  @last_visible_page
end

Instance Method Details

#current_item_countInteger

Get current item count

Returns:

  • (Integer)


76
77
78
# File 'lib/jikanrb/pagination.rb', line 76

def current_item_count
  @items['count'] || 0
end

#has_next_page?Boolean

Check if there's a next page

Returns:

  • (Boolean)


34
35
36
# File 'lib/jikanrb/pagination.rb', line 34

def has_next_page?
  @has_next_page
end

#has_previous_page?Boolean

Check if there's a previous page

Returns:

  • (Boolean)


40
41
42
# File 'lib/jikanrb/pagination.rb', line 40

def has_previous_page?
  @current_page > 1
end

#next_pageInteger?

Get next page number

Returns:

  • (Integer, nil)

    Next page number or nil if no next page



46
47
48
# File 'lib/jikanrb/pagination.rb', line 46

def next_page
  has_next_page? ? @current_page + 1 : nil
end

#per_pageInteger

Get number of items per page

Returns:

  • (Integer)


64
65
66
# File 'lib/jikanrb/pagination.rb', line 64

def per_page
  @items['per_page'] || 25
end

#previous_pageInteger?

Get previous page number

Returns:

  • (Integer, nil)

    Previous page number or nil if no previous page



52
53
54
# File 'lib/jikanrb/pagination.rb', line 52

def previous_page
  has_previous_page? ? @current_page - 1 : nil
end

#total_itemsInteger

Get total number of items

Returns:

  • (Integer)


70
71
72
# File 'lib/jikanrb/pagination.rb', line 70

def total_items
  @items['total'] || 0
end

#total_pagesInteger

Get total number of pages

Returns:

  • (Integer)


58
59
60
# File 'lib/jikanrb/pagination.rb', line 58

def total_pages
  @last_visible_page
end