diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/public_body_category.rb | 53 | ||||
-rw-r--r-- | app/models/public_body_category/category_collection.rb | 54 |
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 |