Sha256: 1444ebb477d33b0ff44ebaeeeacce2db8b2f328051da92f2b3a648f8fe5d7cdf

Contents?: true

Size: 990 Bytes

Versions: 19

Compression:

Stored size: 990 Bytes

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Formatters
    module Plurals
      module Rules

        class << self

          def all
            all_for(TwitterCldr.locale)
          end

          def all_for(locale)
            get_resource(locale)[:keys]
          rescue
            nil
          end

          def rule_for(number, locale = TwitterCldr.locale)
            get_resource(locale)[:rule].call(number)
          rescue
            :other
          end

          protected

          def get_resource(locale)
            locale = TwitterCldr.convert_locale(locale)
            cache_key = TwitterCldr::Utils.compute_cache_key(locale)
            locale_cache[cache_key] ||= eval(TwitterCldr.get_locale_resource(locale, :plurals)[locale])[locale][:i18n][:plural]
          end

          def locale_cache
            @locale_cache ||= {}
          end

        end

      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
twitter_cldr-3.0.10 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-3.0.9 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-3.0.8 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-3.0.7 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-3.0.6 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-3.0.5 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-3.0.4 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-3.0.3 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-3.0.2 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-3.0.1 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-2.4.3 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-3.0.0 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-3.0.0.beta1 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-2.4.2 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-2.4.1 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-2.4.0 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-2.2.0 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-2.1.1 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-2.1.0 lib/twitter_cldr/formatters/plurals/rules.rb