class InciScore::Scorer
Constants
- HAZARD_PERCENT
- WEIGHT_FACTOR
Public Class Methods
new(hazards)
click to toggle source
# File lib/inci_score/scorer.rb, line 8 def initialize(hazards) @hazards = Array(hazards) @size = @hazards.size end
Public Instance Methods
call()
click to toggle source
# File lib/inci_score/scorer.rb, line 13 def call return 0 if @hazards.empty? (100 - avg * HAZARD_PERCENT).round(4) end
Private Instance Methods
avg()
click to toggle source
# File lib/inci_score/scorer.rb, line 18 def avg avg_weighted / @size.to_f end
avg_weighted()
click to toggle source
# File lib/inci_score/scorer.rb, line 22 def avg_weighted return @hazards.reduce(&:+) if same_hazard? weighted.reduce(0.0) do |acc,score| acc += score.value end end
same_hazard?()
click to toggle source
# File lib/inci_score/scorer.rb, line 29 def same_hazard? @hazards.uniq.size == 1 end
weight(index)
click to toggle source
# File lib/inci_score/scorer.rb, line 39 def weight(index) Math.log(index+1, @size * WEIGHT_FACTOR) end
weighted()
click to toggle source
# File lib/inci_score/scorer.rb, line 33 def weighted @hazards.each_with_index.map do |h,i| Score.new(h, weight(i)) end end