Class: InciScore::Computer
- Inherits:
-
Object
- Object
- InciScore::Computer
- Defined in:
- lib/inci_score/computer.rb
Constant Summary collapse
- TOLERANCE =
30.0- DECIMALS =
2
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#ingredients ⇒ Object
readonly
Returns the value of attribute ingredients.
-
#precisions ⇒ Object
readonly
Returns the value of attribute precisions.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
-
#unrecognized ⇒ Object
readonly
Returns the value of attribute unrecognized.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(src:, rules: Normalizer::DEFAULT_RULES) ⇒ Computer
constructor
A new instance of Computer.
- #precision ⇒ Object
- #score ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(src:, rules: Normalizer::DEFAULT_RULES) ⇒ Computer
10 11 12 13 14 15 16 17 18 |
# File 'lib/inci_score/computer.rb', line 10 def initialize(src:, rules: Normalizer::DEFAULT_RULES) @unrecognized = [] @precisions = [] @src = src @rules = rules @ingredients = Normalizer.new(src: src, rules: rules).call @components = fetch_components freeze end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
8 9 10 |
# File 'lib/inci_score/computer.rb', line 8 def components @components end |
#ingredients ⇒ Object (readonly)
Returns the value of attribute ingredients.
8 9 10 |
# File 'lib/inci_score/computer.rb', line 8 def ingredients @ingredients end |
#precisions ⇒ Object (readonly)
Returns the value of attribute precisions.
8 9 10 |
# File 'lib/inci_score/computer.rb', line 8 def precisions @precisions end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
8 9 10 |
# File 'lib/inci_score/computer.rb', line 8 def rules @rules end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
8 9 10 |
# File 'lib/inci_score/computer.rb', line 8 def src @src end |
#unrecognized ⇒ Object (readonly)
Returns the value of attribute unrecognized.
8 9 10 |
# File 'lib/inci_score/computer.rb', line 8 def unrecognized @unrecognized end |
Instance Method Details
#call ⇒ Object
20 21 22 23 24 25 |
# File 'lib/inci_score/computer.rb', line 20 def call Response.new(components: components, unrecognized: unrecognized, score: score, precision: precision) end |
#precision ⇒ Object
31 32 33 |
# File 'lib/inci_score/computer.rb', line 31 def precision (precisions.sum / ingredients.size).round(DECIMALS) end |
#score ⇒ Object
27 28 29 |
# File 'lib/inci_score/computer.rb', line 27 def score Scorer.new(components.map(&:hazard)).call.round(DECIMALS) end |
#valid? ⇒ Boolean
35 36 37 |
# File 'lib/inci_score/computer.rb', line 35 def valid? precision >= TOLERANCE end |