Class: TwitterCldr::Formatters::Rbnf::Plural
- Inherits:
-
Object
- Object
- TwitterCldr::Formatters::Rbnf::Plural
- Defined in:
- lib/twitter_cldr/formatters/numbers/rbnf/plural.rb
Instance Attribute Summary collapse
-
#cases ⇒ Object
readonly
Returns the value of attribute cases.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#plural_type ⇒ Object
readonly
Returns the value of attribute plural_type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(locale, plural_type, cases) ⇒ Plural
constructor
plural_type = cardinal, etc cases = hash of form one: “foo”, two: “bar”.
- #render(number) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(locale, plural_type, cases) ⇒ Plural
plural_type = cardinal, etc cases = hash of form one: “foo”, two: “bar”
28 29 30 31 32 |
# File 'lib/twitter_cldr/formatters/numbers/rbnf/plural.rb', line 28 def initialize(locale, plural_type, cases) @locale = locale @plural_type = plural_type @cases = cases end |
Instance Attribute Details
#cases ⇒ Object (readonly)
Returns the value of attribute cases.
24 25 26 |
# File 'lib/twitter_cldr/formatters/numbers/rbnf/plural.rb', line 24 def cases @cases end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
24 25 26 |
# File 'lib/twitter_cldr/formatters/numbers/rbnf/plural.rb', line 24 def locale @locale end |
#plural_type ⇒ Object (readonly)
Returns the value of attribute plural_type.
24 25 26 |
# File 'lib/twitter_cldr/formatters/numbers/rbnf/plural.rb', line 24 def plural_type @plural_type end |
Class Method Details
.from_string(locale, str) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/twitter_cldr/formatters/numbers/rbnf/plural.rb', line 11 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 |
Instance Method Details
#render(number) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/twitter_cldr/formatters/numbers/rbnf/plural.rb', line 34 def render(number) rule_name = TwitterCldr::Formatters::Plurals::Rules.rule_for( number, locale, plural_type ) cases[rule_name] || cases[:other] end |
#type ⇒ Object
42 43 44 |
# File 'lib/twitter_cldr/formatters/numbers/rbnf/plural.rb', line 42 def type :plural end |