README.md in percentable-0.0.1 vs README.md in percentable-0.1.0

- old
+ new

@@ -1,5 +1,10 @@ +[![Gem Version](https://badge.fury.io/rb/percentable.png)](http://badge.fury.io/rb/percentable) +[![Build Status](https://travis-ci.org/ericroberts/percentable.png?branch=master)](https://travis-ci.org/ericroberts/percentable) +[![Code Climate](https://codeclimate.com/github/ericroberts/percentable.png)](https://codeclimate.com/github/ericroberts/percentable) +[![Coverage Status](https://coveralls.io/repos/ericroberts/percentable/badge.png?branch=master)](https://coveralls.io/r/ericroberts/percentable?branch=master) + # Percentable Small gem to make working with percents easier. ## Installation @@ -35,11 +40,11 @@ ``` ruby percent = Percent.new(10) percent + percent #=> Percent.new(20) percent - percent #=> Percent.new(0) -percent * percent #=> Percent.new(100) +percent * percent #=> Percent.new(1) percent / percent #=> Percent.new(1) ``` And even more importantly, how it works with other Numeric objects: @@ -49,10 +54,20 @@ percent - 10 #=> Percent.new(40) percent * 10 #=> Percent.new(500) percent / 10 #=> Percent.new(5) ``` +And with the number on the other side... + +``` ruby +percent = Percent.new(50) +10 + percent #=> 15 +10 - percent #=> 5 +10 * percent #=> 5 +10 / percent #=> 20 +``` + Repeat steps above for Floats, BigDecimals, etc. It should all work. ### Can I turn other Numerics into Percents? Yes, yes you can. @@ -85,26 +100,54 @@ def returns_a_percent 10 end end -class PercentizedClass +class PercentizedClass < OriginalClass extend Percentable::Percentize percentize :returns_a_percent end percentize_object = PercentizedClass.new percentize_object.returns_a_percent #=> Percent.new(10) ``` +You can do percentize multiple methods at a time: + +``` ruby +class PercentizedClass < OriginalClass + extend Percentable::Percentize + + percentize :method1, :method2 +end +``` + +You can define defaults for when the percentized method returns nil: + +``` ruby +class PercentizedClass < OriginalClass + extend Percentable::Percentize + + percentize :method1, :method2, default: 20 +end + +# assuming method1 on OriginalClass returns nil +percentize_object = PercentizedClass.new +percentize_object.method1 #=> Percent.new(20) +``` + ### OK, but why would I want this? I don't know, all I can tell you is that I found it useful. Instead of writing methods to translate from 0.1 to 10% all over the place, I now have a class to represent everything to do with percents. ### Is that it? -Hey, I only wrote this in a night. Happy to except contributions from others! +Hey, I only wrote this in a night. Happy to accept contributions from others! + +### Your math is totally wrong and you are an idiot. + +That's not a question. I've had a fair bit of discussion with the fine folks at [Boltmade](http://www.boltmade.com) about how it should behave, and the examples you see above are what we settled on. If you would like to propose a change, the best way would be to edit the README to show examples for how you would like it to act. You can also submit a pull request that changes the code, but if you submit the README first we can have a discussion about whether or not it makes sense. I'm not totally sold on the current implementation and would be happy to discuss changes. ## Contributing 1. Fork it ( https://github.com/ericroberts/percentable/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`)