Class: Babelfish::Phrase::PluralForms
- Defined in:
- lib/babelfish/phrase/plural_forms.rb
Overview
Babelfish AST pluralization node.
Class Attribute Summary collapse
-
.compiler ⇒ Object
Returns the value of attribute compiler.
-
.sub_data ⇒ Object
Returns the value of attribute sub_data.
Instance Attribute Summary collapse
-
#compiled ⇒ Object
Returns the value of attribute compiled.
-
#forms ⇒ Object
Returns the value of attribute forms.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
Methods inherited from Node
Constructor Details
This class inherits a constructor from Babelfish::Phrase::Node
Class Attribute Details
.compiler ⇒ Object
Returns the value of attribute compiler.
12 13 14 |
# File 'lib/babelfish/phrase/plural_forms.rb', line 12 def compiler @compiler end |
.sub_data ⇒ Object
Returns the value of attribute sub_data.
12 13 14 |
# File 'lib/babelfish/phrase/plural_forms.rb', line 12 def sub_data @sub_data end |
Instance Attribute Details
#compiled ⇒ Object
Returns the value of attribute compiled.
18 19 20 |
# File 'lib/babelfish/phrase/plural_forms.rb', line 18 def compiled @compiled end |
#forms ⇒ Object
Returns the value of attribute forms.
18 19 20 |
# File 'lib/babelfish/phrase/plural_forms.rb', line 18 def forms @forms end |
#locale ⇒ Object
Returns the value of attribute locale.
18 19 20 |
# File 'lib/babelfish/phrase/plural_forms.rb', line 18 def locale @locale end |
#name ⇒ Object
Returns the value of attribute name.
18 19 20 |
# File 'lib/babelfish/phrase/plural_forms.rb', line 18 def name @name end |
Instance Method Details
#_to_ruby_method(name, index) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/babelfish/phrase/plural_forms.rb', line 45 def _to_ruby_method( name, index ) lambda do |params| value = params[name].to_f rule, strict_forms, regular_forms = PluralForms.sub_data[index] r = nil if value.nan? warn "#{name} parameter is not numeric" r = regular_forms[-1] else r = strict_forms[value] || regular_forms[rule.call(value)] || regular_forms[-1]; end return r if r.kind_of?(String) return '' if r.nil? r.call(params) end end |
#to_ruby_method ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/babelfish/phrase/plural_forms.rb', line 20 def to_ruby_method unless compiled PluralForms.compiler ||= Babelfish::Phrase::Compiler.new forms[:regular].map! do |form| PluralForms.compiler.compile( form ) end new_strict = {} forms[:strict].each_pair do |key, form| new_strict[key] = PluralForms.compiler.compile( form ) end forms[:strict].replace(new_strict) self.compiled = true end rule = Babelfish::Phrase::Pluralizer::find_rule( locale ) PluralForms.sub_data << [ rule, forms[:strict], forms[:regular], ] return _to_ruby_method( name, PluralForms.sub_data.length - 1 ); end |