From 55b5545a0fe5c0fe3007952b7d926980126eccf8 Mon Sep 17 00:00:00 2001
From: echarp <manu@echarp.org>
Date: Sat, 20 Feb 2016 16:53:54 +0100
Subject: [PATCH] Tags organisation is factorised

---
 app/controllers/tags_controller.rb | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 6cb98cd93..b269e6129 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -1,15 +1,11 @@
-# Manage event tags
+# Manage event and organisation tags
 class TagsController < InheritedResources::Base
   has_scope :region, :locality, :daylimit
   has_scope :period, type: :hash, using: [:year, :week]
   has_scope :tag, as: :id
 
   def index
-    @tags = apply_scopes(Event.moderated)
-            .pluck(:tags).map(&:split).flatten
-            .group_by { |i| i }
-            .map { |k, v| [k, v.size] }
-            .sort
+    @tags = organise_tags apply_scopes(Event.moderated)
 
     respond_to do |format|
       format.html
@@ -23,15 +19,22 @@ class TagsController < InheritedResources::Base
   end
 
   def orgas
-    @tags = apply_scopes(Orga.moderated)
-            .pluck(:tags).map(&:split).flatten
-            .group_by { |i| i }
-            .map { |k, v| [k, v.size] }
-            .sort
+    @tags = organise_tags apply_scopes(Orga.moderated)
 
     respond_to do |format|
       format.html
       format.json { render json: @tags }
     end
   end
+
+  private
+
+  # Splits, groups, rejects the less used
+  def organise_tags(tags)
+    tags.pluck(:tags).map(&:split).flatten
+        .group_by { |i| i }
+        .map { |k, v| [k, v.size] }
+        .reject { |_k, v| v <= 3 }
+        .sort
+  end
 end
-- 
GitLab