Module Extlib::Inflection
In: lib/extlib/inflection.rb

English Nouns Number Inflection.

This module provides english singular <-> plural noun inflections.

Methods

External Aliases

singular -> singularize
  Alias for singular (a Railism).
plural -> pluralize
  Alias for plural (a Railism).

Attributes

plural_of  [R] 
singular_of  [R] 

Public Class methods

By default, camelize converts strings to UpperCamelCase.

camelize will also convert ’/’ to ’::’ which is useful for converting paths to namespaces

@example

  "active_record".camelize #=> "ActiveRecord"
  "active_record/errors".camelize #=> "ActiveRecord::Errors"

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"

Convert an English word from singular to plural.

  "boy".plural     #=> boys
  "tomato".plural  #=> tomatoes

Parameters

word<String>:word to pluralize

Returns

<String>:pluralized form of word

Notes

Aliased as pluralize (a Railism)

Define a plurualization rule.

Parameters

singular<String>:ending of the word in singular form
plural<String>:ending of the word in plural form

Examples

Once the following rule is defined: English::Inflect.singular_rule ‘fe’, ‘ves‘

You can see the following results: irb> "wife".plural

> wives

Define a pluralization exception.

Parameters

singular<String>:singular form of the word
plural<String>:plural form of the word

Read prepared pluralization rules.

Define a general rule.

Parameters

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) #

Examples

Once the following rule is defined: English::Inflect.rule ‘y’, ‘ies‘

You can see the following results: irb> "fly".plural

> flies

irb> "cry".plural

> cries

Define a general rule.

Convert an English word from plural to singular.

  "boys".singular      #=> boy
  "tomatoes".singular  #=> tomato

Parameters

word<String>:word to singularize

Returns

<String>:singularized form of word

Notes

Aliased as singularize (a Railism)

Define a singularization rule.

Parameters

singular<String>:ending of the word in singular form
plural<String>:ending of the word in plural form

Examples

Once the following rule is defined: English::Inflect.singular_rule ‘o’, ‘oes‘

You can see the following results: irb> "heroes".singular

> hero

Define a singularization exception.

Parameters

singular<String>:singular form of the word
plural<String>:plural form of the word

Read prepared singularization rules.

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.

Parameters

singular<String>:singular form of the word
plural<String>:plural form of the word

Examples

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‘

[Validate]