Sha256: 941f4c5bcba8610caca901ea5d079206af48b6c0c95709b46e8cd55a0eacc0b9
Contents?: true
Size: 1.19 KB
Versions: 54
Compression:
Stored size: 1.19 KB
Contents
# encoding: UTF-8 # Copyright 2012 Twitter, Inc # http://www.apache.org/licenses/LICENSE-2.0 module TwitterCldr module Formatters module Rbnf class Plural def self.from_string(locale, str) # $(cardinal,one{ tysiąc}few{ tysiące}other{ tysięcy})$ plural_type, cases = str.gsub(/\$\((.*)\)\$/, '\1').split(',') # one{ tysiąc}few{ tysiące}other{ tysięcy} cases = cases.scan(/([\w]+)\{([^}]+)\}/).inject({}) do |ret, case_arr| ret[case_arr.first.to_sym] = case_arr.last ret end new(locale, plural_type.to_sym, cases) end attr_reader :locale, :plural_type, :cases # plural_type = cardinal, etc # cases = hash of form one: "foo", two: "bar" def initialize(locale, plural_type, cases) @locale = locale @plural_type = plural_type @cases = cases end def render(number) rule_name = TwitterCldr::Formatters::Plurals::Rules.rule_for( number, locale, plural_type ) cases[rule_name] || cases[:other] end def type :plural end end end end end
Version data entries
54 entries across 54 versions & 3 rubygems