DivvyUp
A Ruby gem to divvy up a list of item prices into smaller groups, for the purpose of splitting up purchases (somehwat) equally.
Installation
Add this line to your application's Gemfile:
gem 'divvy_up'
And then execute:
$ bundle
Or install it yourself as:
$ gem install divvy_up
Usage
shopping_list = {
orange_juice: 3,
lettuce: 7,
strawberries: 3,
eggs: 2.79,
carrots: 2.5,
onion: 1.25,
tomato: 1.25,
blueberries: 3.99,
butter: 2.69,
pasta_sauce: 2.5,
pepper: 2,
celery: 1.69
}
DivvyUp::List.new(shopping_list).split(3)
# =>
# [
# [{:orange_juice=>3, :eggs=>2.79, :carrots=>2.5, :onion=>1.25, :celery=>1.69}, 11.23],
# [{:lettuce=>7, :strawberries=>3, :tomato=>1.25}, 11.25],
# [{:blueberries=>3.99, :butter=>2.69, :pasta_sauce=>2.5, :pepper=>2}, 11.18]
# ]
Output of #split
method consists of an array of arrays, where each subarray
is a hash of items and the total value of those items.
Contributing
- Fork it ( https://github.com/djpowers/divvy_up/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 a new Pull Request