Chooser
Provides short interface for choosig elements from array of structs.
Installation
Add this line to your application's Gemfile:
gem 'chooser'
And then execute:
$ bundle
Or install it yourself as:
$ gem install chooser
Usage
Given array of struct kind objects.
Person = Struct.new(:name, :profession, :address, :age)
alex = Person.new("Alex", "Programmer", "123 Maple, Anytown NC", 27)
dave = Person.new("Dave", "Programmer", "236 Main", 32)
nick = Person.new("Nick", "Designer", "237 Main st.", 29)
jack = Person.new("Jack", "QA", "1010 Center st.", 29)
people = [alex, dave, nick, jack]
Filtering elements by attribute equality.
people.choose(:profession => "Programmer") # => [alex, dave]
Filtering elements by attribute equality and inclusion.
people.choose(:profession => "Designer", :age => (29..32)) # => [nick]
Filtering elements by matching regexp.
people.choose(:address => /Main/) # => [dave, nick]
Filtering elements by instance evaluating string.
people.choose("age >= 29") # => [dave, nick, jack]
Contributing
- Fork it ( http://github.com/
/chooser/fork ) - Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request