Class: PublishMyData::PaginationParams
- Inherits:
-
Object
- Object
- PublishMyData::PaginationParams
- Defined in:
- lib/publish_my_data/paginator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#page ⇒ Object
Returns the value of attribute page.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(opts = {}) ⇒ PaginationParams
constructor
example opts: => 10, :page => 2, :format => :html.
Constructor Details
#initialize(opts = {}) ⇒ PaginationParams
example opts:
{:per_page => 10, :page => 2, :format => :html}
12 13 14 15 16 17 |
# File 'lib/publish_my_data/paginator.rb', line 12 def initialize(opts={}) self.per_page = (opts[:per_page]).to_i if opts[:per_page] self.page = (opts[:page] || 1).to_i self.offset = self.per_page.to_i * (self.page.to_i-1) if self.per_page self.format = opts[:format] end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
8 9 10 |
# File 'lib/publish_my_data/paginator.rb', line 8 def format @format end |
#offset ⇒ Object
Returns the value of attribute offset.
7 8 9 |
# File 'lib/publish_my_data/paginator.rb', line 7 def offset @offset end |
#page ⇒ Object
Returns the value of attribute page.
5 6 7 |
# File 'lib/publish_my_data/paginator.rb', line 5 def page @page end |
#per_page ⇒ Object
Returns the value of attribute per_page.
6 7 8 |
# File 'lib/publish_my_data/paginator.rb', line 6 def per_page @per_page end |
Class Method Details
.from_request(request) ⇒ Object
19 20 21 |
# File 'lib/publish_my_data/paginator.rb', line 19 def self.from_request(request) self.new(per_page: request.params[:per_page], page: request.params[:page], format: (request.format.to_sym || :html)) end |
Instance Method Details
#==(other) ⇒ Object
23 24 25 26 27 |
# File 'lib/publish_my_data/paginator.rb', line 23 def ==(other) other.page == self.page && other.per_page == self.per_page && other.format == self.format end |