Class: Mack::Utils::Inflector
- Includes:
- Singleton
- Defined in:
- lib/mack-facets/utils/inflector.rb
Overview
This class is used to deal with inflection strings. This means taken a string and make it plural, or singular, etc… Inflectionion rules can be added very easy, and are checked from the bottom up. This means that the last rule is the first rule to be matched. The exception to this, kind of, is ‘irregular’ and ‘uncountable’ rules. The ‘uncountable’ rules are always checked first, then the ‘irregular’ rules, and finally either the ‘singular’ or ‘plural’ rules, depending on what you’re trying to do. Within each of these sets of rules, the last rule in is the first rule matched.
Example:
Mack::Utils::Inflectionor.inflections do |inflect|
inflect.plural(/$/, 's')
inflect.plural(/^(ox)$/i, '\1en')
inflect.plural(/(phenomen|criteri)on$/i, '\1a')
inflect.singular(/s$/i, '')
inflect.singular(/(n)ews$/i, '\1ews')
inflect.singular(/^(.*)ookies$/, '\1ookie')
inflect.irregular('person', 'people')
inflect.irregular('child', 'children')
end
Class Method Summary collapse
-
.inflections ⇒ Object
Yields up Mack::Utils::Inflectionor.instance.
Instance Method Summary collapse
-
#irregular(rule, replacement) ⇒ Object
Adds a irregular rule to the system.
-
#plural(rule, replacement) ⇒ Object
Adds a plural rule to the system.
-
#pluralize(word) ⇒ Object
Returns the singular version of the word, if possible.
-
#singular(rule, replacement) ⇒ Object
Adds a singular rule to the system.
-
#singularize(word) ⇒ Object
Returns the singular version of the word, if possible.
Class Method Details
Instance Method Details
#irregular(rule, replacement) ⇒ Object
58 59 60 61 |
# File 'lib/mack-facets/utils/inflector.rb', line 58 def irregular(rule, replacement) Extlib::Inflection.rule(rule, replacement) Extlib::Inflection.word(rule, replacement) end |
#plural(rule, replacement) ⇒ Object
35 36 37 |
# File 'lib/mack-facets/utils/inflector.rb', line 35 def plural(rule, replacement) Extlib::Inflection.plural_rule(rule, replacement) end |
#pluralize(word) ⇒ Object
79 80 81 |
# File 'lib/mack-facets/utils/inflector.rb', line 79 def pluralize(word) Extlib::Inflection.plural(word) end |
#singular(rule, replacement) ⇒ Object
47 48 49 |
# File 'lib/mack-facets/utils/inflector.rb', line 47 def singular(rule, replacement) Extlib::Inflection.singular_rule(rule, replacement) end |
#singularize(word) ⇒ Object
69 70 71 |
# File 'lib/mack-facets/utils/inflector.rb', line 69 def singularize(word) Extlib::Inflection.singular(word) end |