Class: FreshBooks::Page
- Inherits:
-
Object
- Object
- FreshBooks::Page
- Defined in:
- lib/freshbooks/list_proxy.rb
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#initialize(page, per_page, total) ⇒ Page
constructor
A new instance of Page.
- #next_page? ⇒ Boolean
-
#page_number(position) ⇒ Object
Get the page number that this element is on given the number of elements per page.
- #pages ⇒ Object
-
#position_number(position) ⇒ Object
Get the position number of this element based relative to the current page.
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
#page ⇒ Object (readonly)
Returns the value of attribute page.
40 41 42 |
# File 'lib/freshbooks/list_proxy.rb', line 40 def page @page end |
#per_page ⇒ Object (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 |
#total ⇒ Object (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
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 |
#pages ⇒ Object
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 |