public class Inflector
extends java.lang.Object
Constructor and Description |
---|
Inflector() |
Modifier and Type | Method and Description |
---|---|
void |
addIrregular(java.lang.String singular,
java.lang.String plural) |
void |
addPluralize(java.lang.String rule,
java.lang.String replacement) |
void |
addSingularize(java.lang.String rule,
java.lang.String replacement) |
void |
addUncountable(java.lang.String... words) |
java.lang.String |
capitalize(java.lang.String words)
Returns a copy of the input with the first character converted to uppercase and the remainder to lowercase.
|
static Inflector |
getInstance() |
java.lang.String |
humanize(java.lang.String lowerCaseAndUnderscoredWords,
java.lang.String... removableTokens)
Capitalizes the first word and turns underscores into spaces and strips trailing "_id" and any supplied removable tokens.
|
boolean |
isUncountable(java.lang.String word)
Determine whether the supplied word is considered uncountable by the
pluralize and
singularize methods. |
MultipleInflection |
of(int count) |
Inflection |
of(java.lang.String word) |
java.lang.String |
pluralize(java.lang.Object word)
Returns the plural form of the word in the string.
|
java.lang.String |
pluralize(java.lang.Object word,
int count) |
java.lang.String |
singularize(java.lang.Object word)
Returns the singular form of the word in the string.
|
java.lang.String |
titleCase(java.lang.String words,
java.lang.String... removableTokens)
Capitalizes all the words and replaces some characters in the string to create a nicer looking title.
|
java.lang.String |
underscore(java.lang.String camelCaseWord,
char... delimiterChars)
Makes an underscored form from the expression in the string method.
|
public static Inflector getInstance()
public Inflection of(java.lang.String word)
public MultipleInflection of(int count)
public java.lang.String pluralize(java.lang.Object word)
inflector.pluralize("post") #=> "posts" inflector.pluralize("octopus") #=> "octopi" inflector.pluralize("sheep") #=> "sheep" inflector.pluralize("words") #=> "words" inflector.pluralize("the blue mailman") #=> "the blue mailmen" inflector.pluralize("CamelOctopus") #=> "CamelOctopi"Note that if the
Object.toString()
is called on the supplied object, so this method works for non-strings, too.word
- the word that is to be pluralized.singularize(Object)
public java.lang.String pluralize(java.lang.Object word, int count)
public java.lang.String singularize(java.lang.Object word)
inflector.singularize("posts") #=> "post" inflector.singularize("octopi") #=> "octopus" inflector.singularize("sheep") #=> "sheep" inflector.singularize("words") #=> "word" inflector.singularize("the blue mailmen") #=> "the blue mailman" inflector.singularize("CamelOctopi") #=> "CamelOctopus"Note that if the
Object.toString()
is called on the supplied object, so this method works for non-strings, too.word
- the word that is to be pluralized.pluralize(Object)
public java.lang.String capitalize(java.lang.String words)
words
- the word to be capitalizedpublic java.lang.String humanize(java.lang.String lowerCaseAndUnderscoredWords, java.lang.String... removableTokens)
titleCase(String, String[])
, this is meant for creating pretty output.
Examples:
inflector.humanize("employee_salary") #=> "Employee salary" inflector.humanize("author_id") #=> "Author"
lowerCaseAndUnderscoredWords
- the input to be humanizedremovableTokens
- optional array of tokens that are to be removedtitleCase(String, String[])
public java.lang.String underscore(java.lang.String camelCaseWord, char... delimiterChars)
inflector.underscore("activeRecord") #=> "active_record" inflector.underscore("ActiveRecord") #=> "active_record" inflector.underscore("firstName") #=> "first_name" inflector.underscore("FirstName") #=> "first_name" inflector.underscore("name") #=> "name" inflector.underscore("The.firstName") #=> "the_first_name"
camelCaseWord
- the camel-cased word that is to be converted;delimiterChars
- optional characters that are used to delimit word boundaries (beyond capitalization)public java.lang.String titleCase(java.lang.String words, java.lang.String... removableTokens)
humanize(String, String[])
, this is meant for creating pretty output.
Examples:
inflector.titleCase("man from the boondocks") #=> "Man From The Boondocks" inflector.titleCase("x-men: the last stand") #=> "X Men: The Last Stand"
words
- the input to be turned into title caseremovableTokens
- optional array of tokens that are to be removedpublic boolean isUncountable(java.lang.String word)
pluralize
and
singularize
methods.word
- the wordpublic void addPluralize(java.lang.String rule, java.lang.String replacement)
public void addSingularize(java.lang.String rule, java.lang.String replacement)
public void addIrregular(java.lang.String singular, java.lang.String plural)
public void addUncountable(java.lang.String... words)