Sha256: 079ab81d7fe9c6d5af7dc20384ac147015f5a24c9fd9470c9276b2aa7be392b2

Contents?: true

Size: 868 Bytes

Versions: 4

Compression:

Stored size: 868 Bytes

Contents

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

class TwitterCldr.RBNFPlural
  @from_string : (string, locale = TwitterCldr.Settings.locale()) ->
    # $(cardinal,one{ tysiąc}few{ tysiące}other{ tysięcy})$
    [plural_type, cases_map] = string.match(/\$\((.*)\)\$/)[1].split(',')
    cases = {}

    # one{ tysiąc}few{ tysiące}other{ tysięcy}
    split_regex = /([\w]+)\{([^}]+)\}/g
    while match = split_regex.exec(cases_map)
      cases[match[1]] = match[2]

    new TwitterCldr.RBNFPlural(locale, plural_type, cases)

  # plural_type = cardinal, etc
  # cases = hash of form one: "foo", two: "bar"
  constructor : (@locale, @plural_type, @cases) ->
    @type = "plural"

  type : ->
    @type

  render : (number) ->
    rule_name = TwitterCldr.PluralRules.rule_for(number, @plural_type)
    @cases[rule_name] || @cases["other"]

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
twitter_cldr_js-3.3.0 lib/twitter_cldr/js/mustache/implementation/numbers/rbnf/plural.coffee
twitter_cldr_js-3.2.0 lib/twitter_cldr/js/mustache/implementation/numbers/rbnf/plural.coffee
twitter_cldr_js-3.1.1 lib/twitter_cldr/js/mustache/implementation/numbers/rbnf/plural.coffee
twitter_cldr_js-3.1.0 lib/twitter_cldr/js/mustache/implementation/numbers/rbnf/plural.coffee