2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-11-21 12:33:39 +01:00
|
|
|
class Procedure::EstimatedDelayComponent < ApplicationComponent
|
2023-11-28 17:04:19 +01:00
|
|
|
delegate :distance_of_time_in_words, to: :helpers
|
|
|
|
|
2023-11-21 12:33:39 +01:00
|
|
|
def initialize(procedure:)
|
|
|
|
@procedure = procedure
|
2023-11-28 17:04:19 +01:00
|
|
|
@fastest, @mean, @slow = @procedure.stats_usual_traitement_time
|
2023-11-21 12:33:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def estimation_present?
|
|
|
|
@fastest && @mean && @slow
|
|
|
|
end
|
|
|
|
|
|
|
|
def render?
|
2024-02-08 12:47:58 +01:00
|
|
|
return false if @procedure.declarative_accepte?
|
|
|
|
|
2023-11-21 12:33:39 +01:00
|
|
|
estimation_present?
|
|
|
|
end
|
2023-11-28 17:04:19 +01:00
|
|
|
|
|
|
|
def cleaned_nearby_estimation
|
|
|
|
[@fastest, @mean, @slow]
|
|
|
|
.map { distance_of_time_in_words(_1) }
|
|
|
|
.uniq
|
|
|
|
.zip(['fast_html', 'mean_html', 'slow_html'])
|
|
|
|
.each do |estimation, i18n_key|
|
|
|
|
yield(estimation, i18n_key)
|
|
|
|
end
|
|
|
|
end
|
2023-11-21 12:33:39 +01:00
|
|
|
end
|