I can see a possible performance optimization with declaring 2 arrays and iterating the $fake_widgets
only once, but how else can I make the following conditional string building more elegant in Ruby?
pending_coloring = $fake_widgets.select do |widget|
widget[:status] == 'awaiting_coloring' && widget[:owner_color] == @owner.id
end
pending_processing = $fake_widgets.select do |widget|
widget[:status] == 'awaiting_processing' && widget[:owner_color] == @owner.id
end
notification_text = "You have "
if pending_coloring.size == 1
notification_text += "#{pending_coloring.size} widget to color"
elsif pending_coloring.size > 1
notification_text += "#{pending_coloring.size} widgets to color"
end
if pending_coloring.size > 0 && pending_processing.size > 0
notification_text += " and "
end
if pending_processing.size == 1
notification_text += "#{pending_processing.size} widget to process"
elsif pending_processing.size > 1
notification_text += "#{pending_processing.size} widgets to process"
end
notification_text += ". Go to widget dashboard"