Class: Frontline::Inflector::Inflections
- Inherits:
-
Object
- Object
- Frontline::Inflector::Inflections
- Defined in:
- lib/frontline/inflect.rb
Instance Attribute Summary collapse
-
#plurals ⇒ Object
readonly
Returns the value of attribute plurals.
-
#singulars ⇒ Object
readonly
Returns the value of attribute singulars.
-
#uncountables ⇒ Object
readonly
Returns the value of attribute uncountables.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Inflections
constructor
A new instance of Inflections.
-
#plural(rule, replacement) ⇒ Object
Specifies a new pluralization rule and its replacement.
-
#singular(rule, replacement) ⇒ Object
Specifies a new singularization rule and its replacement.
-
#uncountable(*words) ⇒ Object
Add uncountable words that shouldn’t be attempted inflected.
Constructor Details
#initialize ⇒ Inflections
Returns a new instance of Inflections.
14 15 16 |
# File 'lib/frontline/inflect.rb', line 14 def initialize @plurals, @singulars, @uncountables = [], [], [] end |
Instance Attribute Details
#plurals ⇒ Object (readonly)
Returns the value of attribute plurals.
12 13 14 |
# File 'lib/frontline/inflect.rb', line 12 def plurals @plurals end |
#singulars ⇒ Object (readonly)
Returns the value of attribute singulars.
12 13 14 |
# File 'lib/frontline/inflect.rb', line 12 def singulars @singulars end |
#uncountables ⇒ Object (readonly)
Returns the value of attribute uncountables.
12 13 14 |
# File 'lib/frontline/inflect.rb', line 12 def uncountables @uncountables end |
Class Method Details
.instance(locale = :en) ⇒ Object
8 9 10 |
# File 'lib/frontline/inflect.rb', line 8 def self.instance(locale = :en) @__instance__[locale] ||= new end |
Instance Method Details
#plural(rule, replacement) ⇒ Object
Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression. The replacement should always be a string that may include references to the matched data from the rule.
22 23 24 25 26 |
# File 'lib/frontline/inflect.rb', line 22 def plural(rule, replacement) @uncountables.delete(rule) if rule.is_a?(String) @uncountables.delete(replacement) @plurals.unshift([rule, replacement]) end |
#singular(rule, replacement) ⇒ Object
Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression. The replacement should always be a string that may include references to the matched data from the rule.
32 33 34 35 36 |
# File 'lib/frontline/inflect.rb', line 32 def singular(rule, replacement) @uncountables.delete(rule) if rule.is_a?(String) @uncountables.delete(replacement) @singulars.unshift([rule, replacement]) end |
#uncountable(*words) ⇒ Object
Add uncountable words that shouldn’t be attempted inflected.
uncountable 'money'
uncountable 'money', 'information'
uncountable %w( money information rice )
43 44 45 |
# File 'lib/frontline/inflect.rb', line 43 def uncountable(*words) (@uncountables << words).flatten! end |