Class: RestFtpDaemon::Paginate
- Inherits:
-
Object
- Object
- RestFtpDaemon::Paginate
- Includes:
- CommonHelpers
- Defined in:
- lib/rest-ftp-daemon/paginate.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
Returns the value of attribute all.
-
#filter ⇒ Object
writeonly
Class options.
Instance Method Summary collapse
- #browser ⇒ Object
-
#initialize(data) ⇒ Paginate
constructor
A new instance of Paginate.
- #page=(raw_page) ⇒ Object
- #subset ⇒ Object
Methods included from CommonHelpers
#dashboard_url, #exception_to_error, #format_bytes, #identifier, #underscore
Constructor Details
#initialize(data) ⇒ Paginate
Returns a new instance of Paginate.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rest-ftp-daemon/paginate.rb', line 9 def initialize data # Defaults @pages = 0 @total = 0 @data = [] @filter = '' @page = 1 @pages = 1 @all = false # Ensure data set is countable return unless data.is_a? Enumerable @data = data # Count elements @total = @data.count # Count pages @pages = (@total.to_f / DEFAULT_PAGE_SIZE).ceil @pages = 1 if @pages < 1 end |
Instance Attribute Details
#all ⇒ Object
Returns the value of attribute all.
7 8 9 |
# File 'lib/rest-ftp-daemon/paginate.rb', line 7 def all @all end |
#filter=(value) ⇒ Object (writeonly)
Class options
6 7 8 |
# File 'lib/rest-ftp-daemon/paginate.rb', line 6 def filter=(value) @filter = value end |
Instance Method Details
#browser ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/rest-ftp-daemon/paginate.rb', line 35 def browser return if @all out = [] 1.upto(@pages) do |p| out << link(p) end out.join() end |
#page=(raw_page) ⇒ Object
31 32 33 |
# File 'lib/rest-ftp-daemon/paginate.rb', line 31 def page= raw_page @page = [1, raw_page.to_i, @pages].sort[1] end |
#subset ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/rest-ftp-daemon/paginate.rb', line 45 def subset return @data if @all size = DEFAULT_PAGE_SIZE.to_i offset = (@page-1) * size @data[offset, size] end |