diff options
author | seb <seb@seb-U36JC> | 2011-11-24 09:21:36 +0000 |
---|---|---|
committer | seb <seb@seb-U36JC> | 2011-11-24 09:21:36 +0000 |
commit | a4e533f1588a5d34dca4ab462b58ddd83eed37c5 (patch) | |
tree | 58bb3b57ec5664e094ae151c18b6c1915256e364 /lib/public_body_categories.rb | |
parent | d473fce1d0451c913d3ef697d3b45bd58c6fff54 (diff) | |
parent | e649c2a7f19d0a75206149d886ff47b3ccda4e91 (diff) |
Merge branch 'develop' into xapian-dcabo
Conflicts:
spec/models/xapian_spec.rb
Diffstat (limited to 'lib/public_body_categories.rb')
-rw-r--r-- | lib/public_body_categories.rb | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/lib/public_body_categories.rb b/lib/public_body_categories.rb index 844e14e67..21a021d39 100644 --- a/lib/public_body_categories.rb +++ b/lib/public_body_categories.rb @@ -6,14 +6,39 @@ # # $Id: public_body_categories.rb,v 1.1 2009-09-14 14:45:48 francis Exp $ -module PublicBodyCategories +class PublicBodyCategories + + attr_reader :with_description, :with_headings, :tags, :by_tag, :singular_by_tag + + def initialize(categories) + @with_headings = categories + # Arranged in different ways for different sorts of displaying + @with_description = @with_headings.select() { |a| a.instance_of?(Array) } + @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] + end - CATEGORIES_WITH_HEADINGS = [] - - # Arranged in different ways for different sorts of displaying - CATEGORIES_WITH_DESCRIPTION = CATEGORIES_WITH_HEADINGS.select() { |a| a.instance_of?(Array) } - CATEGORIES = CATEGORIES_WITH_DESCRIPTION.map() { |a| a[0] } - CATEGORIES_BY_TAG = Hash[*CATEGORIES_WITH_DESCRIPTION.map() { |a| a[0..1] }.flatten] - CATEGORY_SINGULAR_BY_TAG = Hash[*CATEGORIES_WITH_DESCRIPTION.map() { |a| [a[0],a[2]] }.flatten] -end + def PublicBodyCategories.get + load_categories() if @@CATEGORIES.nil? + @@CATEGORIES[I18n.locale.to_s] || @@CATEGORIES[I18n.default_locale.to_s] || PublicBodyCategories.new([]) + end + # Called from the data files themselves + def PublicBodyCategories.add(locale, categories) + @@CATEGORIES[locale.to_s] = PublicBodyCategories.new(categories) + end + + private + @@CATEGORIES = nil + + def PublicBodyCategories.load_categories() + @@CATEGORIES = {} if @@CATEGORIES.nil? + I18n.available_locales.each do |locale| + begin + load "public_body_categories_#{locale}.rb" + rescue MissingSourceFile + end + end + end +end
\ No newline at end of file |