Class: FreshBooks::Page

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, per_page, total) ⇒ Page

Returns a new instance of Page.



42
43
44
45
46
# File 'lib/freshbooks/list_proxy.rb', line 42

def initialize(page, per_page, total)
  @page = page.to_i
  @per_page = per_page.to_i
  @total = total.to_i
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



40
41
42
# File 'lib/freshbooks/list_proxy.rb', line 40

def page
  @page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



40
41
42
# File 'lib/freshbooks/list_proxy.rb', line 40

def per_page
  @per_page
end

#totalObject (readonly)

Returns the value of attribute total.



40
41
42
# File 'lib/freshbooks/list_proxy.rb', line 40

def total
  @total
end

Instance Method Details

#next_page?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/freshbooks/list_proxy.rb', line 66

def next_page?
  page < pages
end

#page_number(position) ⇒ Object

Get the page number that this element is on given the number of elements per page



49
50
51
# File 'lib/freshbooks/list_proxy.rb', line 49

def page_number(position)
  (position / per_page) + 1
end

#pagesObject



58
59
60
61
62
63
64
# File 'lib/freshbooks/list_proxy.rb', line 58

def pages
  pages = total / per_page
  if (total % per_page) != 0
    pages += 1
  end
  pages
end

#position_number(position) ⇒ Object

Get the position number of this element based relative to the current page



54
55
56
# File 'lib/freshbooks/list_proxy.rb', line 54

def position_number(position)
  position - ((page - 1) * per_page)
end