review: style

This commit is contained in:
sebastiencarceles 2022-12-05 09:49:03 +01:00
parent 9dfb498806
commit a5c1c68a91

View file

@ -11,20 +11,16 @@ class PrefillParams
private private
def build_prefill_values def build_prefill_values
# Builds: [{ stable_id: 1, value: "a value" }, { stable_id: 2, value: "another value"}] value_by_stable_id = @params
stable_ids_and_values = .to_unsafe_hash
@params .map { |typed_id, value| [stable_id_from_typed_id(typed_id), value] }
.to_unsafe_hash .filter { |stable_id, value| stable_id.present? && value.present? }
.map { |typed_id, value| { stable_id: stable_id_from_typed_id(typed_id), value: value } } .to_h
.filter { _1[:stable_id].present? && _1[:value].present? }
@dossier @dossier
.find_champs_by_stable_ids(stable_ids_and_values.map { _1[:stable_id] }) .find_champs_by_stable_ids(value_by_stable_id.keys)
.map do |champ| .map { |champ| [champ, value_by_stable_id[champ.stable_id]] }
value = stable_ids_and_values.find { _1[:stable_id] == champ.stable_id }[:value] .map { |champ, value| PrefillValue.new(champ:, value:) }
PrefillValue.new(champ: champ, value: value)
end
end end
def stable_id_from_typed_id(typed_id) def stable_id_from_typed_id(typed_id)