module GemsBond::Examination

Examines gem sanity

Constants

BOUNDARIES
RESULTS
SCORES

Private Instance Methods

soften(value, comparison) click to toggle source

Returns a score with a logarithmic approach @param value [Float] the value for inspected data @param comparison [Numeric] the value giving the maximal score (1) @returns [Float] @example

soften(10.to_f,100.to_f) #=> 0.46

The idea is that a gem with half as much stars

than rails gem (which is very high and stands for comparison here)
should get a very high score but still be behind rails itself
# File lib/gems_bond/examination.rb, line 85
def soften(value, comparison)
  # returns a shaped curve
  sigmoid = ->(x) { 1 / (1 + Math.exp(-x * 10)) }
  # simoid boundaries are [0.5, 1]
  #   so remove 0.5 and multiply by 2 to have boundaries [0, 1]
  (sigmoid.call(value / comparison) - 0.5) * 2
end
weighted_average(scores) click to toggle source

Returns an average after including weight for each value @param scores [Array<Array<Float, Integer>>] each hash looks like [value, weight] @returns [Float] @example

weighted_average([[4.0, 2], [1.0, 3]]) #=> 2.2
# File lib/gems_bond/examination.rb, line 98
def weighted_average(scores)
  acc = 0
  weight = 0
  scores.each do |score|
    value, weighting = score
    next unless value

    acc += value * weighting
    weight += weighting
  end.compact
  return if weight.zero?

  acc / weight
end