From d92f97716a50312f8d1cbb29f8c5ee2073a695ee Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 16 Jun 2020 18:17:39 +0100 Subject: [PATCH] Extract compute_for and thus resolve the rubocop complexity issue --- app/models/calculator/flexi_rate.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/calculator/flexi_rate.rb b/app/models/calculator/flexi_rate.rb index 4f56f10a41..76ae53379a 100644 --- a/app/models/calculator/flexi_rate.rb +++ b/app/models/calculator/flexi_rate.rb @@ -31,10 +31,16 @@ module Calculator return 0 if max.zero? if items_count > max - (max - 1) * preferred_additional_item.to_f + preferred_first_item.to_f + compute_for(max - 1) elsif items_count <= max - (items_count - 1) * preferred_additional_item.to_f + preferred_first_item.to_f + compute_for(items_count - 1) end end + + private + + def compute_for(count) + count * preferred_additional_item.to_f + preferred_first_item.to_f + end end end