Module: Folio::Ordinal::Page

Included in:
BasicPage
Defined in:
lib/folio/ordinal/page.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.createObject



79
80
81
# File 'lib/folio/ordinal/page.rb', line 79

def self.create
  Folio::Ordinal::BasicPage.new
end

Instance Method Details

#current_page=(value) ⇒ Object



41
42
43
# File 'lib/folio/ordinal/page.rb', line 41

def current_page=(value)
  @current_page = value.to_i
end

#first_pageObject



33
34
35
# File 'lib/folio/ordinal/page.rb', line 33

def first_page
  1
end

#last_pageObject



37
38
39
# File 'lib/folio/ordinal/page.rb', line 37

def last_page
  (total_pages || next_page) ? total_pages : current_page
end

#next_pageObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/folio/ordinal/page.rb', line 49

def next_page
  if total_pages && current_page >= total_pages
    # known number of pages and we've reached the last one. no next page
    # (even if explicitly set)
    nil
  elsif total_pages || !defined?(@next_page)
    # (1) known number of pages and we haven't reached the last one
    #     (because we're not in the branch above), or
    # (2) unknown number of pages, but nothing set, so we assume an
    #     infinite stream
    # so there's a next page, and it's the one after this one
    current_page + 1
  else
    # just use what they set
    @next_page
  end
end

#next_page=(value) ⇒ Object



45
46
47
# File 'lib/folio/ordinal/page.rb', line 45

def next_page=(value)
  @next_page = value && value.to_i
end

#offsetObject



75
76
77
# File 'lib/folio/ordinal/page.rb', line 75

def offset
  (current_page - 1) * per_page
end

#ordinal_pagesObject Also known as: ordinal_pages?



28
29
30
# File 'lib/folio/ordinal/page.rb', line 28

def ordinal_pages
  true
end

#out_of_bounds?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/folio/ordinal/page.rb', line 71

def out_of_bounds?
  (current_page < first_page) || (last_page && current_page > last_page) || false
end

#previous_pageObject



67
68
69
# File 'lib/folio/ordinal/page.rb', line 67

def previous_page
  current_page > first_page ? current_page - 1 : nil
end