Class: InciScore::Scorer

Inherits:
Object
  • Object
show all
Defined in:
lib/inci_score/scorer.rb

Constant Summary collapse

HAZARD_RATIO =
25
WEIGHT_FACTOR =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hazards) ⇒ Scorer

Returns a new instance of Scorer.



10
11
12
13
14
# File 'lib/inci_score/scorer.rb', line 10

def initialize(hazards)
  @hazards = Array(hazards)
  @size = @hazards.size
  freeze
end

Instance Attribute Details

#hazardsObject (readonly)

Returns the value of attribute hazards.



8
9
10
# File 'lib/inci_score/scorer.rb', line 8

def hazards
  @hazards
end

#sizeObject (readonly)

Returns the value of attribute size.



8
9
10
# File 'lib/inci_score/scorer.rb', line 8

def size
  @size
end

Instance Method Details

#callObject



16
17
18
19
# File 'lib/inci_score/scorer.rb', line 16

def call
  return 0 if hazards.empty?
  (100 - avg * HAZARD_RATIO).round(4)
end