Sha256: 3f731dd92dcc215e5466d04b755815751f553cc1bd981e9858ad67627d1cfa85

Contents?: true

Size: 828 Bytes

Versions: 2

Compression:

Stored size: 828 Bytes

Contents

module JsonTestData
  module NumberHelper
    def adjust_for_maximum(number:, maximum: nil, step_size: nil)
      return number unless (maximum && number >= maximum)

      num = !!step_size ? number - step_size : maximum - 1
      adjust_for_maximum(number: num, maximum: maximum, step_size: step_size)
    end

    def adjust_for_minimum(number:, minimum:, step_size: nil)
      return number unless minimum && minimum >= number

      num = !!step_size ? number + step_size : minimum + 1
      adjust_for_minimum(number: num, minimum: minimum, step_size: step_size)
    end

    def between(min:, max:, integer: false)
      return integer ? mean(min, max).to_i : mean(min, max)
    end

    def mean(*numbers)
      numbers.inject(:+).to_f.quo(numbers.length)
    end

    def infinity
      Math.atanh(1)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
json_test_data-0.3.0.beta lib/json_test_data/data_structures/helpers/number_helper.rb
json_test_data-0.1.0 lib/json_test_data/data_structures/helpers/number_helper.rb