Sha256: f489ca5c8aa21c945c652b69948b19bc1bb97f8932fca2443c9f620fae59f315
Contents?: true
Size: 1.96 KB
Versions: 2
Compression:
Stored size: 1.96 KB
Contents
# 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 [![Build Status](https://travis-ci.org/ankane/hightop.svg?branch=master)](https://travis-ci.org/ankane/hightop) ## 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) ``` ## User Input If passing user input as the column, be sure to sanitize it first [like you must](https://rails-sqli.org/) with `group`. ```ruby column = params[:column] # check against permitted columns raise "Unpermitted column" unless ["column_a", "column_b"].include?(column) User.top(column) ``` ## 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 features To get started with development and testing: ```sh git clone https://github.com/ankane/hightop.git cd hightop bundle install bundle exec rake test ```
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hightop-0.2.4 | README.md |
hightop-0.2.3 | README.md |