aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2014-09-24 17:44:43 +0100
committerLouise Crow <louise.crow@gmail.com>2014-09-24 17:44:43 +0100
commitfd82802023fec28c0e467c0ba2820489d35ddc9c (patch)
tree93c4ebb80c547b1837d5479782d418607c89a9f0 /app/models
parent7b7f5dfa21f669b75552e946bedc598174fd71db (diff)
fixup! Replace existing PublicBodyCategories functionality with db models PublicBodyCategory and PublicBodyHeading
Diffstat (limited to 'app/models')
-rw-r--r--app/models/public_body_category.rb53
-rw-r--r--app/models/public_body_category/category_collection.rb54
2 files changed, 54 insertions, 53 deletions
diff --git a/app/models/public_body_category.rb b/app/models/public_body_category.rb
index 74b239463..b019673c4 100644
--- a/app/models/public_body_category.rb
+++ b/app/models/public_body_category.rb
@@ -167,57 +167,4 @@ class PublicBodyCategory < ActiveRecord::Base
end
end
-# replicate original file-based PublicBodyCategories functionality
-class CategoryCollection
- include Enumerable
- extend Forwardable
- def_delegators :@categories, :each, :<<
-
- def initialize
- @categories = []
- end
-
- def with_headings
- @categories
- end
-
- def with_description
- @categories.select() { |a| a.instance_of?(Array) }
- end
-
- def tags
- tags = with_description.map() { |a| a[0] }
- end
-
- def by_tag
- Hash[*with_description.map() { |a| a[0..1] }.flatten]
- end
-
- def singular_by_tag
- Hash[*with_description.map() { |a| [a[0],a[2]] }.flatten]
- end
-
- def by_heading
- output = {}
- heading = nil
- @categories.each do |row|
- if row.is_a?(Array)
- output[heading] << row[0]
- else
- heading = row
- output[heading] = []
- end
- end
- output
- end
- def headings
- output = []
- @categories.each do |row|
- unless row.is_a?(Array)
- output << row
- end
- end
- output
- end
-end
diff --git a/app/models/public_body_category/category_collection.rb b/app/models/public_body_category/category_collection.rb
new file mode 100644
index 000000000..8286e2710
--- /dev/null
+++ b/app/models/public_body_category/category_collection.rb
@@ -0,0 +1,54 @@
+# replicate original file-based PublicBodyCategories functionality
+class PublicBodyCategory::CategoryCollection
+ include Enumerable
+ extend Forwardable
+ def_delegators :@categories, :each, :<<
+
+ def initialize
+ @categories = []
+ end
+
+ def with_headings
+ @categories
+ end
+
+ def with_description
+ @categories.select() { |a| a.instance_of?(Array) }
+ end
+
+ def tags
+ tags = with_description.map() { |a| a[0] }
+ end
+
+ def by_tag
+ Hash[*with_description.map() { |a| a[0..1] }.flatten]
+ end
+
+ def singular_by_tag
+ Hash[*with_description.map() { |a| [a[0],a[2]] }.flatten]
+ end
+
+ def by_heading
+ output = {}
+ heading = nil
+ @categories.each do |row|
+ if row.is_a?(Array)
+ output[heading] << row[0]
+ else
+ heading = row
+ output[heading] = []
+ end
+ end
+ output
+ end
+
+ def headings
+ output = []
+ @categories.each do |row|
+ unless row.is_a?(Array)
+ output << row
+ end
+ end
+ output
+ end
+end