Project

ish

0.0
No commit activity in last 3 years
No release in over 3 years
Adds random fuzzy helper methods to various ruby classes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

Runtime

>= 0
 Project Readme

ish

Gem Version Build Status Code Climate

Ish is a ruby gem for when random 'fuzzy' numeric/time results are desired. Some quick examples:

# integers always return integers
100.ish # => 99
100.ish # => 104

# the default precision is 0.05, meaning the plus/minus range (offset)
# is 5% of the input number (so default offset of 100 is 5)
# can override either via params
100.ish(precision: 0.5) # => 135   (50-150 range)
100.ish(offset: 90)     # => 17    (10-190 range)

# floats return floats
(1.0).ish # => 1.0017225780713743  (0.95-1.05 range)
(50.0).ish(precision: 0.5) # => 37.131807291843145
(100.0).ish(offset: 2)     # => 101.44457832200423

# precision can't be calculated from a time object, so we default to offset of 5 minutes
Time.now       # => 2013-07-30 11:55:19 -0500
Time.now.ish   # => 2013-07-30 11:53:33 -0500 (+/- 5 minutes from original time)

# the offset param is in seconds
Time.now.ish(offset: 1000000) # => 2013-07-26 16:31:06 -0500  (+/- 1000000 seconds from original time)

# if the integer would yield an offest less than 1, then 1 is the offset
0.ish  # => 1
0.ish  # => 0
-1.ish # => -2

If you use active support, times are even more fun!

2.hours.ish # => 7215 seconds (+/- 6 minutes)
1.day.from_now # => Wed, 31 Jul 2013 16:43:05 UTC +00:00
1.day.ish.from_now # => Wed, 31 Jul 2013 17:50:44 UTC +00:00 (+/- 72 min)
1.hour.ish(offset: 10.minutes).from_now # => Tue, 30 Jul 2013 18:03:20 UTC +00:00 (+/- 10 min)

Install

# Add the following to you Gemfile
gem 'ish'

# Update your bundle
bundle install

Advanced Usage

If you don't care for the default precision or time offsets, you can override either like so:

Ish.default_precision = 0.5  # default is 0.05
Ish.default_time_offset_seconds = 100000000000  # default is 300

All calls to ish without params will now use those values