Class: Wallaby::Sorting::HashBuilder
- Inherits:
-
Object
- Object
- Wallaby::Sorting::HashBuilder
- Defined in:
- lib/services/wallaby/sorting/hash_builder.rb
Overview
Turn a string e.g.‘’name asc,id desc’‘ into sort hash e.g.`’asc’, id: ‘desc’‘
Constant Summary collapse
- SORT_REGEX =
/(([^\s,]+)\s+(asc|desc))\s*,?\s*/i
Class Method Summary collapse
-
.build(sort_string) ⇒ Hash
Turn a string e.g.‘’name asc,id desc’‘ into sort hash e.g.`’asc’, id: ‘desc’‘.
Class Method Details
.build(sort_string) ⇒ Hash
Turn a string e.g.‘’name asc,id desc’‘ into sort hash e.g.`’asc’, id: ‘desc’‘
13 14 15 16 17 18 19 |
# File 'lib/services/wallaby/sorting/hash_builder.rb', line 13 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 |