Module | Extlib::Inflection |
In: |
lib/extlib/inflection.rb
|
This module provides english singular <-> plural noun inflections.
plural_of | [R] | |
singular_of | [R] |
Take an underscored name and make it into a camelized name
@example
"egg_and_hams".classify #=> "EggAndHam" "enlarged_testes".classify #=> "EnlargedTestis" "post".classify #=> "Post"
Constantize tries to find a declared constant with the name specified in the string. It raises a NameError when the name is not in CamelCase or is not initialized.
@example
"Module".constantize #=> Module "Class".constantize #=> Class
Removes the module part from the expression in the string
@example
"ActiveRecord::CoreExtensions::String::Inflections".demodulize #=> "Inflections" "Inflections".demodulize #=> "Inflections"
Creates a foreign key name from a class name.
@example
"Message".foreign_key #=> "message_id" "Admin::Post".foreign_key #=> "post_id"
Capitalizes the first word and turns underscores into spaces and strips _id. Like titleize, this is meant for creating pretty output.
@example
"employee_salary" #=> "Employee salary" "author_id" #=> "Author"
Define a general rule.
singular<String>: | ending of the word in singular form |
plural<String>: | ending of the word in plural form |
whole_word<Boolean>: | for capitalization, since words can be capitalized (Man => Men) # |
Once the following rule is defined: English::Inflect.rule ‘y’, ‘ies‘
You can see the following results: irb> "fly".plural
irb> "cry".plural
Define a general rule.
Create the name of a table like Rails does for models to table names. This method uses the pluralize method on the last word in the string.
@example
"RawScaledScorer".tableize #=> "raw_scaled_scorers" "EnlargedTestis".tableize #=> "enlarged_testes" "egg_and_ham".tableize #=> "egg_and_hams" "fancyCategory".tableize #=> "fancy_categories"
The reverse of camelize. Makes an underscored form from the expression in the string.
Changes ’::’ to ’/’ to convert namespaces to paths.
@example
"ActiveRecord".underscore #=> "active_record" "ActiveRecord::Errors".underscore #=> active_record/errors
Defines a general inflection exception case.
singular<String>: | singular form of the word |
plural<String>: | plural form of the word |
Here we define erratum/errata exception case:
English::Inflect.word "erratum", "errata"
In case singular and plural forms are the same omit second argument on call:
English::Inflect.word ‘information‘