diff options
author | Robin Houston <robin.houston@gmail.com> | 2012-09-07 12:51:42 +0100 |
---|---|---|
committer | Robin Houston <robin.houston@gmail.com> | 2012-09-07 12:51:42 +0100 |
commit | c690679f5e55d908a0f91b0d9b3276ae3f748b2d (patch) | |
tree | cbe46b2e859aa6f59d39a110d997274091004a24 /lib/public_body_categories.rb | |
parent | 67a3a43cc26f8ad7218f33a13af04c3c74347866 (diff) | |
parent | dd39dbc580b1447758a6d3b9231ce09c9b3dcdf3 (diff) |
Merge branch 'wdtk' of git.mysociety.org:/data/git/public/alaveteli into wdtk
Diffstat (limited to 'lib/public_body_categories.rb')
-rw-r--r-- | lib/public_body_categories.rb | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/lib/public_body_categories.rb b/lib/public_body_categories.rb index b8058bf9e..b4aa71a40 100644 --- a/lib/public_body_categories.rb +++ b/lib/public_body_categories.rb @@ -7,9 +7,15 @@ # $Id: public_body_categories.rb,v 1.1 2009-09-14 14:45:48 francis Exp $ class PublicBodyCategories - - attr_reader :with_description, :with_headings, :tags, :by_tag, :singular_by_tag - + + attr_reader :with_description, + :with_headings, + :tags, + :by_tag, + :singular_by_tag, + :by_heading, + :headings + def initialize(categories) @with_headings = categories # Arranged in different ways for different sorts of displaying @@ -17,8 +23,21 @@ class PublicBodyCategories @tags = @with_description.map() { |a| a[0] } @by_tag = Hash[*@with_description.map() { |a| a[0..1] }.flatten] @singular_by_tag = Hash[*@with_description.map() { |a| [a[0],a[2]] }.flatten] + @by_heading = {} + heading = nil + @headings = [] + @with_headings.each do |row| + if ! row.instance_of?(Array) + heading = row + @headings << row + @by_heading[row] = [] + else + @by_heading[heading] << row[0] + end + end end + def PublicBodyCategories.get load_categories if @@CATEGORIES.empty? @@CATEGORIES[I18n.locale.to_s] || @@CATEGORIES[I18n.default_locale.to_s] || PublicBodyCategories.new([]) @@ -28,10 +47,10 @@ class PublicBodyCategories def PublicBodyCategories.add(locale, categories) @@CATEGORIES[locale.to_s] = PublicBodyCategories.new(categories) end - + private @@CATEGORIES = {} - + def PublicBodyCategories.load_categories() I18n.available_locales.each do |locale| begin |