java.lang.Object
net.thucydides.model.util.Inflector
Transforms words to singular, plural, humanized (human readable), underscore, camel case, or ordinal form. This is inspired by
the Inflector class in Ruby on Rails, which is distributed under the Rails license.
- Author:
- Randall Hauch
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncapitalize(String words) Returns a copy of the input with the first character converted to uppercase and the remainder to lowercase.firstUpperCase(String words) static InflectorCapitalizes the first word and turns underscores into spaces and strips trailing "_id" and any supplied removable tokens.static Inflectorprotected voidMakes an kebab-cased expression of a string method.of(int count) of(long count) Returns the plural form of the word in the string.singularize(Object word) Returns the singular form of the word in the string.underscore(String camelCaseWord, char... delimiterChars) Makes an underscored form from the expression in the string method.
-
Constructor Details
-
Inflector
public Inflector()
-
-
Method Details
-
getInstance
-
inflection
-
of
-
of
-
of
-
pluralize
Returns the plural form of the word in the string.Examples:
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.- Parameters:
word- the word that is to be pluralized.- Returns:
- the pluralized form of the word, or the word itself if it could not be pluralized
- See Also:
-
pluralize
-
singularize
Returns the singular form of the word in the string.Examples:
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.- Parameters:
word- the word that is to be pluralized.- Returns:
- the pluralized form of the word, or the word itself if it could not be pluralized
- See Also:
-
capitalize
Returns a copy of the input with the first character converted to uppercase and the remainder to lowercase.- Parameters:
words- the word to be capitalized- Returns:
- the string with the first character capitalized and the remaining characters lowercased
-
firstUpperCase
-
humanize
Capitalizes the first word and turns underscores into spaces and strips trailing "_id" and any supplied removable tokens. LiketitleCase(String, String[]), this is meant for creating pretty output.Examples:
inflector.humanize("employee_salary") #=> "Employee salary" inflector.humanize("author_id") #=> "Author"- Parameters:
lowerCaseAndUnderscoredWords- the input to be humanizedremovableTokens- optional array of tokens that are to be removed- Returns:
- the humanized string
- See Also:
-
underscore
Makes an underscored form from the expression in the string method. Also changes any characters that match the supplied delimiters into underscore.Examples:
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"- Parameters:
camelCaseWord- the camel-cased word that is to be converted;delimiterChars- optional characters that are used to delimit word boundaries (beyond capitalization)- Returns:
- a lower-cased version of the input, with separate words delimited by the underscore character.
-
kebabCase
Makes an kebab-cased expression of a string method.- Parameters:
camelCaseWord- the camel-cased word that is to be converted;delimiterChars- optional characters that are used to delimit word boundaries (beyond capitalization)- Returns:
- a kebab-cased version of the input, with separate words delimited by the hyphen character.
-
initialize
protected void initialize()
-