Sha256: e508184ed29e908d0f6aeea556260ea0d1c18f6d26d3ec22ccd6fe4b24d7ad47

Contents?: true

Size: 976 Bytes

Versions: 5

Compression:

Stored size: 976 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.get_locale)
          end

          def all_for(locale)
            locale = TwitterCldr.convert_locale(locale.to_sym)
            get_resource(locale)[locale][:i18n][:plural][:keys]
          rescue
            nil
          end

          def rule_for(number, locale = TwitterCldr.get_locale)
            locale = TwitterCldr.convert_locale(locale.to_sym)
            get_resource(locale)[locale][:i18n][:plural][:rule].call(number)
          rescue
            :other
          end

          protected

          def get_resource(locale)
            locale = TwitterCldr.convert_locale(locale)
            eval(TwitterCldr.get_locale_resource(locale, :plurals)[locale])
          end

        end

      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
twitter_cldr-1.5.0 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-1.4.1 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-1.4.0 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-1.3.6 lib/twitter_cldr/formatters/plurals/rules.rb
twitter_cldr-1.3.0 lib/twitter_cldr/formatters/plurals/rules.rb