Class: Wallaby::Sorting::HashBuilder
- Inherits:
-
Object
- Object
- Wallaby::Sorting::HashBuilder
- Defined in:
- lib/services/wallaby/sorting/hash_builder.rb
Overview
Turn a string ‘’name asc,id desc’‘ into sort hash
Constant Summary collapse
- SORT_REGEX =
/(([^\s,]+)\s+(asc|desc))\s*,?\s*/i
Class Method Summary collapse
Class Method Details
.build(sort_string) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/services/wallaby/sorting/hash_builder.rb', line 7 def self.build(sort_string) ::ActiveSupport::HashWithIndifferentAccess.new.tap do |hash| (sort_string || EMPTY_STRING).scan SORT_REGEX do |_, key, order| hash[key] = order end end end |