The Inflector transforms words from singular to plural, class names to table
names, modularized class names to ones without, and class names to foreign keys.
Inflections can be localized, the default english inflections for pluralization,
singularization, and uncountable words are kept in
lib/inflections/en.php
.
public static
ICanBoogie\Inflector
|
#
get( string $locale = 'en' )
Returns an inflector for the specified locale.
Returns an inflector for the specified locale.
Note: Inflectors are shared for the same locale. If you need to alter an
inflector you MUST clone it first.
Parameters
Returns
|
protected
|
|
public
|
|
public
|
|
public
string
|
#
pluralize( string $word )
Returns the plural form of the word in the string.
Returns the plural form of the word in the string.
$this->pluralize('post'); // "posts"
$this->pluralize('children'); // "child"
$this->pluralize('sheep'); // "sheep"
$this->pluralize('words'); // "words"
$this->pluralize('CamelChild'); // "CamelChild"
Parameters
Returns
string
|
public
string
|
#
singularize( string $word )
The reverse of ICanBoogie\pluralize() , returns the singular form of a word in a
string.
$this->singularize('posts'); // "post"
$this->singularize('childred'); // "child"
$this->singularize('sheep'); // "sheep"
$this->singularize('word'); // "word"
$this->singularize('CamelChildren'); // "CamelChild"
Parameters
Returns
string
|
public
string
|
#
camelize( string $term, boolean $downcase_first_letter = false )
By default, ICanBoogie\camelize() converts strings to UpperCamelCase.
ICanBoogie\camelize() will also convert "/" to "\" which is useful for converting
paths to namespaces.
$this->camelize('active_model'); // 'ActiveModel'
$this->camelize('active_model', true); // 'activeModel'
$this->camelize('active_model/errors'); // 'ActiveModel\Errors'
$this->camelize('active_model/errors', true); // 'activeModel\Errors'
As a rule of thumb you can think of ICanBoogie\camelize() as the inverse of ICanBoogie\underscore() , though there are cases where that does not hold:
$this->camelize($this->underscore('SSLError')); // "SslError"
Parameters
- $term
string $term
- $downcase_first_letter
boolean $downcase_first_letter If false then ICanBoogie\camelize() produces
lowerCamelCase.
Returns
string
|
public
string
|
#
underscore( string $camel_cased_word )
Makes an underscored, lowercase form from the expression in the string.
Makes an underscored, lowercase form from the expression in the string.
Changes "\" to "/" to convert namespaces to paths.
$this->underscore('ActiveModel'); // 'active_model'
$this->underscore('ActiveModel\Errors'); // 'active_model/errors'
As a rule of thumb you can think of ICanBoogie\underscore() as the inverse of
ICanBoogie\camelize() , though there are cases where that does not hold:
$this->camelize($this->underscore('SSLError')); // "SslError"
Parameters
- $camel_cased_word
string $camel_cased_word
Returns
string
|
public
string
|
#
humanize( string $lower_case_and_underscored_word )
Capitalizes the first word and turns underscores into spaces and strips a
trailing "_id", if any. Like ICanBoogie\titleize() , this is meant for creating
pretty output.
Capitalizes the first word and turns underscores into spaces and strips a
trailing "_id", if any. Like ICanBoogie\titleize() , this is meant for creating
pretty output.
$this->humanize('employee_salary'); // "Employee salary"
$this->humanize('author_id'); // "Author"
Parameters
- $lower_case_and_underscored_word
string $lower_case_and_underscored_word
Returns
string
|
public
string
|
#
titleize( string $str )
Capitalizes all the words and replaces some characters in the string to
create a nicer looking title. ICanBoogie\titleize() is meant for creating pretty
output. It is not used in the Rails internals.
Capitalizes all the words and replaces some characters in the string to
create a nicer looking title. ICanBoogie\titleize() is meant for creating pretty
output. It is not used in the Rails internals.
$this->titleize('man from the boondocks'); // "Man From The Boondocks"
$this->titleize('x-men: the last stand'); // "X Men: The Last Stand"
$this->titleize('TheManWithoutAPast'); // "The Man Without A Past"
$this->titleize('raiders_of_the_lost_ark'); // "Raiders Of The Lost Ark"
Parameters
Returns
string
|
public
string
|
#
dasherize( string $underscored_word )
Replaces underscores with dashes in the string.
Replaces underscores with dashes in the string.
$this->dasherize('puni_puni'); // "puni-puni"
Parameters
- $underscored_word
string $underscored_word
Returns
string
|
public
string
|
#
hyphenate( string $str )
Makes an hyphenated, lowercase form from the expression in the string.
|
public
|
#
ordinal( mixed $number )
Returns the suffix that should be added to a number to denote the position in
an ordered sequence such as 1st, 2nd, 3rd, 4th.
Returns the suffix that should be added to a number to denote the position in
an ordered sequence such as 1st, 2nd, 3rd, 4th.
$this->ordinal(1); // "st"
$this->ordinal(2); // "nd"
$this->ordinal(1002); // "nd"
$this->ordinal(1003); // "rd"
$this->ordinal(-11); // "th"
$this->ordinal(-1021); // "st"
|
public
|
#
ordinalize( mixed $number )
Turns a number into an ordinal string used to denote the position in an
ordered sequence such as 1st, 2nd, 3rd, 4th.
Turns a number into an ordinal string used to denote the position in an
ordered sequence such as 1st, 2nd, 3rd, 4th.
$this->ordinalize(1); // "1st"
$this->ordinalize(2); // "2nd"
$this->ordinalize(1002); // "1002nd"
$this->ordinalize(1003); // "1003rd"
$this->ordinalize(-11); // "-11th"
$this->ordinalize(-1021); // "-1021st"
|