Class: ApiMe::Sorting
- Inherits:
-
Object
- Object
- ApiMe::Sorting
- Defined in:
- lib/api_me/sorting.rb
Instance Attribute Summary collapse
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#sort_criteria ⇒ Object
Returns the value of attribute sort_criteria.
-
#sort_reverse ⇒ Object
Returns the value of attribute sort_reverse.
Instance Method Summary collapse
-
#initialize(scope:, sort_params:) ⇒ Sorting
constructor
A new instance of Sorting.
- #results ⇒ Object
- #sort_meta ⇒ Object
Constructor Details
#initialize(scope:, sort_params:) ⇒ Sorting
Returns a new instance of Sorting.
5 6 7 8 9 10 11 12 |
# File 'lib/api_me/sorting.rb', line 5 def initialize(scope:, sort_params:) self.scope = scope if sort_params self.sort_criteria = sort_params[:criteria] self.sort_reverse = sort_params[:reverse] end end |
Instance Attribute Details
#scope ⇒ Object
Returns the value of attribute scope.
3 4 5 |
# File 'lib/api_me/sorting.rb', line 3 def scope @scope end |
#sort_criteria ⇒ Object
Returns the value of attribute sort_criteria.
3 4 5 |
# File 'lib/api_me/sorting.rb', line 3 def sort_criteria @sort_criteria end |
#sort_reverse ⇒ Object
Returns the value of attribute sort_reverse.
3 4 5 |
# File 'lib/api_me/sorting.rb', line 3 def sort_reverse @sort_reverse end |
Instance Method Details
#results ⇒ Object
14 15 16 |
# File 'lib/api_me/sorting.rb', line 14 def results sorting? ? sort.scope : scope end |
#sort_meta ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/api_me/sorting.rb', line 18 def return Hash.new unless sorting? { criteria: sort_criteria.is_blank? || sort_criteria === "" ? default_sort_criteria : sort_criteria, reverse: sort_reverse, record_count: scope.size, total_records: scope.total_count, } end |