Class: PaginatedTable::Page
- Inherits:
-
Object
- Object
- PaginatedTable::Page
- Defined in:
- lib/paginated_table/page.rb
Constant Summary collapse
- SORT_DIRECTIONS =
%w(asc desc)
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#sort_column ⇒ Object
readonly
Returns the value of attribute sort_column.
-
#sort_direction ⇒ Object
readonly
Returns the value of attribute sort_direction.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Page
constructor
A new instance of Page.
- #page_for_number(number) ⇒ Object
- #page_for_sort_column(new_sort_column) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Page
Returns a new instance of Page.
13 14 15 16 17 18 19 20 21 |
# File 'lib/paginated_table/page.rb', line 13 def initialize(attributes) @number = Integer(attributes[:number] || 1) raise ArgumentError unless @number > 0 @rows = Integer(attributes[:rows] || PaginatedTable.configuration.rows_per_page) raise ArgumentError unless @rows > 0 @sort_column = attributes[:sort_column] || 'id' @sort_direction = attributes[:sort_direction] || 'asc' raise ArgumentError unless SORT_DIRECTIONS.include?(@sort_direction) end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
6 7 8 |
# File 'lib/paginated_table/page.rb', line 6 def number @number end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
6 7 8 |
# File 'lib/paginated_table/page.rb', line 6 def rows @rows end |
#sort_column ⇒ Object (readonly)
Returns the value of attribute sort_column.
6 7 8 |
# File 'lib/paginated_table/page.rb', line 6 def sort_column @sort_column end |
#sort_direction ⇒ Object (readonly)
Returns the value of attribute sort_direction.
6 7 8 |
# File 'lib/paginated_table/page.rb', line 6 def sort_direction @sort_direction end |
Class Method Details
.opposite_sort_direction(sort_direction) ⇒ Object
8 9 10 11 |
# File 'lib/paginated_table/page.rb', line 8 def self.opposite_sort_direction(sort_direction) index = SORT_DIRECTIONS.index(sort_direction) SORT_DIRECTIONS[index - 1] end |
Instance Method Details
#page_for_number(number) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/paginated_table/page.rb', line 23 def page_for_number(number) Page.new( :number => number, :rows => rows, :sort_column => sort_column, :sort_direction => sort_direction ) end |
#page_for_sort_column(new_sort_column) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/paginated_table/page.rb', line 32 def page_for_sort_column(new_sort_column) if sort_column == new_sort_column new_sort_direction = self.class.opposite_sort_direction(sort_direction) else new_sort_direction = nil end Page.new( :number => 1, :rows => rows, :sort_column => new_sort_column, :sort_direction => new_sort_direction ) end |