Flow.Inflector class
Part of Flow
Converts words between their singular and plural forms. The rules of a language are declared
inside of a Flow.Inflector:inflections block as pattern replacements, irregular words and
uncountable words; the English rules ship with Flux. Flow.Inflector:pluralize and
Flow.Inflector:singularize apply the rules of the current language to the last part of a
snake_case word. ActiveRecord uses them to derive the names of database tables from the names
of models, turning 'user' into 'users', and the names of foreign keys from the names of tables.
Summary
Methods
Methods
Defines the inflection rules of a language. The rules added inside of the callback (and anything looked up afterward) belong to that language.
Flow.Inflector:inflections('en', function(inflect)
inflect:plural(i'^(ox)$', '%1en')
inflect:singular(i'(quiz)zes$', '%1')
inflect:irregular('person', 'people')
inflect:uncountable(w'data ammo equipment')
end)
Parameters
- lang String language code
- func Function receives the inflector
Returns
- Flow::Inflector self, for chaining
Adds a word that does not follow the regular rules to the current language.
Parameters
- word String singular form
- replacement String plural form
Returns
- Flow::Inflector self, for chaining
Returns the irregular words of the current language.
Returns
- Map plural forms by singular form
Returns the irregular words of the current language, the other way around.
Returns
- Map singular forms by plural form
Flow.Inflector:plural(expression, replacement)
shared packages/flow/lib/inflector/sh_inflector.lua:79Adds a pluralization rule to the current language.
Parameters
- expression String Lua pattern that the singular form must match
- replacement String what to replace the match with, can refer to captures
Returns
- Flow::Inflector self, for chaining
Converts a word to its plural form using the rules of the current language. Only the last part of a snake_case word is converted.
Parameters
- word String
Returns
- String plural form
Returns the pluralization rules of the current language.
Returns
- List<Map> rules with the expression and replacement keys
Flow.Inflector:singular(expression, replacement)
shared packages/flow/lib/inflector/sh_inflector.lua:94Adds a singularization rule to the current language.
Parameters
- expression String Lua pattern that the plural form must match
- replacement String what to replace the match with, can refer to captures
Returns
- Flow::Inflector self, for chaining
Converts a word to its singular form using the rules of the current language. Only the last part of a snake_case word is converted.
Parameters
- word String
Returns
- String singular form
Returns the singularization rules of the current language.
Returns
- List<Map> rules with the expression and replacement keys
Adds words that have no separate plural form to the current language.
Parameters
- words String/List<String> a word or a list of words
Returns
- Flow::Inflector self, for chaining
Returns the uncountable words of the current language.
Returns
- Map true by word