Class: Videojuicer::Resource::Collection
- Defined in:
- lib/videojuicer/resource/collection.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#total ⇒ Object
Returns the value of attribute total.
Class Method Summary collapse
-
.offset_from_page_number(page, limit) ⇒ Integer
Provides an offset when given a page number.
Instance Method Summary collapse
-
#initialize(objects, total, offset, limit) ⇒ Collection
constructor
A new instance of Collection.
- #page_count ⇒ Object
- #page_number ⇒ Object
Constructor Details
#initialize(objects, total, offset, limit) ⇒ Collection
Returns a new instance of Collection.
16 17 18 19 20 21 22 |
# File 'lib/videojuicer/resource/collection.rb', line 16 def initialize(objects, total, offset, limit) clear objects.each {|o| self << o } self.total = total self.offset = offset self.limit = limit end |
Instance Attribute Details
#limit ⇒ Object
Returns the value of attribute limit.
12 13 14 |
# File 'lib/videojuicer/resource/collection.rb', line 12 def limit @limit end |
#offset ⇒ Object
Returns the value of attribute offset.
13 14 15 |
# File 'lib/videojuicer/resource/collection.rb', line 13 def offset @offset end |
#total ⇒ Object
Returns the value of attribute total.
14 15 16 |
# File 'lib/videojuicer/resource/collection.rb', line 14 def total @total end |
Class Method Details
.offset_from_page_number(page, limit) ⇒ Integer
Provides an offset when given a page number
35 36 37 38 39 |
# File 'lib/videojuicer/resource/collection.rb', line 35 def self.offset_from_page_number page, limit page = page.to_i return 0 if page == 1 (page - 1) * limit.to_i end |
Instance Method Details
#page_count ⇒ Object
41 42 43 44 |
# File 'lib/videojuicer/resource/collection.rb', line 41 def page_count return 1 if limit.nil? or total.nil? or total < 1 (total.to_f/limit.to_f).ceil end |
#page_number ⇒ Object
46 47 48 49 |
# File 'lib/videojuicer/resource/collection.rb', line 46 def page_number return 1 if limit.nil? or offset.nil? or offset < 1 ((offset+1).to_f/limit.to_f).ceil end |