Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mynameisrufus/sorted
Sorting library
https://github.com/mynameisrufus/sorted
Last synced: 3 months ago
JSON representation
Sorting library
- Host: GitHub
- URL: https://github.com/mynameisrufus/sorted
- Owner: mynameisrufus
- License: mit
- Created: 2010-07-13T04:23:52.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2019-06-26T08:21:12.000Z (over 5 years ago)
- Last Synced: 2024-09-17T23:47:46.497Z (4 months ago)
- Language: Ruby
- Homepage:
- Size: 151 KB
- Stars: 63
- Watchers: 3
- Forks: 27
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ruby-toolbox - sorted - Data sorting library, used by other libs to construct queries and more (Active Record Plugins / Pagination)
README
# Sorted
[![Build Status](https://travis-ci.org/mynameisrufus/sorted.svg?branch=master)](https://travis-ci.org/mynameisrufus/sorted)
Sorted at it's core is a set of objects that let you sort many different
attributes in weird and wonderful ways.## Example
The secret sauce is the `Sorted::Set` object, in this example we 'toggle' email:
```ruby
require 'sorted/set'a = Sorted::Set.new([['email', 'asc'], ['name', 'asc']])
b = Sorted::Set.new([['email', 'asc'], ['phone', 'asc']])s = a.direction_intersect(b)
s.to_a #=> [['email', 'desc'], ['phone', 'asc'], ['name', 'asc']]
```The best way to think about this is to imagine a spreed sheet and what happens
when you sort by various columns, `Sorted::Set` pretty much just does that.## Parsers/Encoders
Parsers return a `Sorted::Set` that can then be used by an encoder:
```ruby
require 'sorted/uri_query'set = Sorted::URIQuery.parse('name_asc!email_asc')
Sorted::SQLQuery.encode(set) #=> 'name ASC email ASC'
```Currently implemented:
* `Sorted::SQLQuery`
* `Sorted::URIQuery`
* `Sorted::JSONQuery`
* `Sorted::ElasticsearchQuery`
* `Sorted::ParamsQuery`## Projects
* Mongoid https://github.com/dleavitt/sorted-mongoid
* ActiveRecord https://github.com/mynameisrufus/sorted-activerecord
* ActionView https://github.com/mynameisrufus/sorted-actionview