Module: Ish
- Defined in:
- lib/ish.rb,
lib/ish/time.rb,
lib/ish/fixnum.rb,
lib/ish/number.rb,
lib/ish/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
- .default_precision ⇒ Object
- .default_precision=(val) ⇒ Object
-
.default_time_offset_seconds ⇒ Object
5 min = 300 sec.
- .default_time_offset_seconds=(val) ⇒ Object
- .fuzzify(num, opts = {}) ⇒ Object
- .fuzzify_time(time, opts = {}) ⇒ Object
- .rand_float_offset(offset) ⇒ Object
- .rand_integer_offset(offset) ⇒ Object
Class Method Details
.default_precision ⇒ Object
8 9 10 |
# File 'lib/ish.rb', line 8 def self.default_precision @default_precision ||= 0.05 end |
.default_precision=(val) ⇒ Object
12 13 14 |
# File 'lib/ish.rb', line 12 def self.default_precision=(val) @default_precision = val end |
.default_time_offset_seconds ⇒ Object
5 min = 300 sec
17 18 19 |
# File 'lib/ish.rb', line 17 def self.default_time_offset_seconds @default_time_offset_seconds ||= 300 end |
.default_time_offset_seconds=(val) ⇒ Object
21 22 23 |
# File 'lib/ish.rb', line 21 def self.default_time_offset_seconds=(val) @default_time_offset_seconds = val end |
.fuzzify(num, opts = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ish.rb', line 25 def self.fuzzify(num, opts={}) raise "argument must be a number!" if !num.respond_to?(:abs) offset = offset_from_opts(num, opts) # min offset for fixnum is 1 offset = 1 if num.is_a?(Fixnum) && offset.abs < 1 rand_offset = if num.is_a? Fixnum rand_integer_offset(offset) else rand_float_offset(offset) end result = num + rand_offset # Fixnum in, fixnum out, aka FIFO if num.is_a? Fixnum result.to_i else result end end |
.fuzzify_time(time, opts = {}) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/ish.rb', line 49 def self.fuzzify_time(time, opts={}) raise 'argument must be a time!' if !time.is_a? Time offset = time_offset_from_opts(opts) rand_offset = rand_integer_offset(offset) time + rand_offset end |
.rand_float_offset(offset) ⇒ Object
63 64 65 66 67 |
# File 'lib/ish.rb', line 63 def self.rand_float_offset(offset) term = offset * rand # rand is between 0.0 and 1.0 term *= -1 if rand(2) == 0 # minus half the time term end |
.rand_integer_offset(offset) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/ish.rb', line 56 def self.rand_integer_offset(offset) range = offset + 1 # because rand(1) only returns 0 term = rand(range) term *= -1 if rand(2) == 0 # minus half the time term end |