class PavementConditionIndex::Lookups::CorrectedDeductValues
Public Class Methods
new(pavement_type:nil, q:nil)
click to toggle source
# File lib/pavement_condition_index/lookups/corrected_deduct_values.rb, line 5 def initialize(pavement_type:nil, q:nil) @pavement_type = pavement_type @q = "q#{q}".to_sym end
Public Instance Methods
call(total_deduct_value)
click to toggle source
# File lib/pavement_condition_index/lookups/corrected_deduct_values.rb, line 10 def call(total_deduct_value) coefficients = PavementConditionIndex::Lookups::CalculatedCorrectedDeductCoefficients::COEFFICIENTS[@pavement_type][:coefficients][@q] total_deduct_value = total_deduct_value.clamp(0.0,200.0) return evaluate_polynomial(*coefficients).call(total_deduct_value).clamp(0.0,100.0) end
Private Instance Methods
evaluate_polynomial(*coefficients)
click to toggle source
# File lib/pavement_condition_index/lookups/corrected_deduct_values.rb, line 18 def evaluate_polynomial(*coefficients) Proc.new {|x| coefficients.map.with_index{|c,i| c*(x**i)}.reduce(:+)} end