Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ankane/hightop
A nice shortcut for group count queries
https://github.com/ankane/hightop
Last synced: about 17 hours ago
JSON representation
A nice shortcut for group count queries
- Host: GitHub
- URL: https://github.com/ankane/hightop
- Owner: ankane
- License: mit
- Created: 2014-05-11T23:28:58.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2024-12-29T21:52:03.000Z (about 2 months ago)
- Last Synced: 2025-02-13T17:10:05.591Z (8 days ago)
- Language: Ruby
- Homepage:
- Size: 93.8 KB
- Stars: 479
- Watchers: 6
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-rails-gems - ankane / hightop
README
# Hightop
A nice shortcut for group count queries
```ruby
Visit.top(:browser)
# {
# "Chrome" => 63,
# "Safari" => 50,
# "Firefox" => 34
# }
```Works with Active Record, Mongoid, arrays and hashes
[](https://github.com/ankane/hightop/actions)
## Installation
Add this line to your application’s Gemfile:
```ruby
gem "hightop"
```## Options
Limit the results
```ruby
Visit.top(:referring_domain, 10)
```Include nil values
```ruby
Visit.top(:search_keyword, nil: true)
```Works with multiple groups
```ruby
Visit.top([:city, :browser])
```And expressions
```ruby
Visit.top(Arel.sql("LOWER(referring_domain)"))
```And distinct
```ruby
Visit.top(:city, distinct: :user_id)
```And min count
```ruby
Visit.top(:city, min: 10)
```## Arrays and Hashes
Arrays
```ruby
["up", "up", "down"].top
```Hashes
```ruby
{a: "up", b: "up", c: "down"}.top { |k, v| v }
```Limit the results
```ruby
["up", "up", "down"].top(1)
```Include nil values
```ruby
[nil, nil, "down"].top(nil: true)
```Min count
```ruby
["up", "up", "down"].top(min: 2)
```## History
View the [changelog](https://github.com/ankane/hightop/blob/master/CHANGELOG.md)
## Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- [Report bugs](https://github.com/ankane/hightop/issues)
- Fix bugs and [submit pull requests](https://github.com/ankane/hightop/pulls)
- Write, clarify, or fix documentation
- Suggest or add new featuresTo get started with development:
```sh
git clone https://github.com/ankane/hightop.git
cd hightop
bundle install
bundle exec rake test
```