Jungle.Inflexor v0.1.3 Jungle.Inflexor.Humanizations View Source

Link to this section Summary

Functions

Tweaks an attribute name for display to end users.

# # Specifically, performs these transformations: # # Applies human inflection rules to the argument. # Deletes leading underscores, if any. # Removes a “_id” suffix if present. # Replaces underscores with spaces, if any. # Downcases all words except acronyms. # Capitalizes the first word. # The capitalization of the first word can be turned off by setting the # +:capitalize+ option to false (default is true). # # The trailing ‘_id’ can be kept and capitalized by setting the # optional parameter +keep_id_suffix+ to true (default is false)

Capitalizes all the words and replaces some characters in the string to

# create a nicer looking title. +titleize+ is meant for creating pretty # output. It is not used in the Rails internals. # # The trailing ‘_id’,’Id’.. can be kept and capitalized by setting the # optional parameter +keep_id_suffix+ to true. # By default, this parameter is false. # # +titleize+ is also aliased as +titlecase+. # # titleize(‘man from the boondocks’) # => “Man From The Boondocks” # titleize(‘x-men: the last stand’) # => “X Men: The Last Stand” # titleize(‘TheManWithoutAPast’) # => “The Man Without A Past” # titleize(‘raiders_of_the_lost_ark’) # => “Raiders Of The Lost Ark” # titleize(‘string_ending_with_id’, keep_id_suffix: true) # => “String Ending With Id”

Examples

Link to this section Functions

Link to this function humanize(string, opts \\ []) View Source

# Tweaks an attribute name for display to end users. # # Specifically, performs these transformations: # # Applies human inflection rules to the argument. # Deletes leading underscores, if any. # Removes a “_id” suffix if present. # Replaces underscores with spaces, if any. # Downcases all words except acronyms. # Capitalizes the first word. # The capitalization of the first word can be turned off by setting the # +:capitalize+ option to false (default is true). # # The trailing ‘_id’ can be kept and capitalized by setting the # optional parameter +keep_id_suffix+ to true (default is false).

Examples

iex> Jungle.Inflexor.humanize("employee_salary")
"Employee salary"
iex> Jungle.Inflexor.humanize("author_id")
"Author"
iex> Jungle.Inflexor.humanize("author_id", [capitalize: false])
"author"
iex> Jungle.Inflexor.humanize("_id")
"Id"
iex> Jungle.Inflexor.humanize("author_id", [keep_id_suffix: true])
"Author Id"

# If “SSL” was defined to be an acronym:

iex> Jungle.Inflexor.humanize("ssl_error")
"SSL error"
Link to this function titleize(string, opts \\ []) View Source

# Capitalizes all the words and replaces some characters in the string to # create a nicer looking title. +titleize+ is meant for creating pretty # output. It is not used in the Rails internals. # # The trailing ‘_id’,’Id’.. can be kept and capitalized by setting the # optional parameter +keep_id_suffix+ to true. # By default, this parameter is false. # # +titleize+ is also aliased as +titlecase+. # # titleize(‘man from the boondocks’) # => “Man From The Boondocks” # titleize(‘x-men: the last stand’) # => “X Men: The Last Stand” # titleize(‘TheManWithoutAPast’) # => “The Man Without A Past” # titleize(‘raiders_of_the_lost_ark’) # => “Raiders Of The Lost Ark” # titleize(‘string_ending_with_id’, keep_id_suffix: true) # => “String Ending With Id”

Examples

iex> Jungle.Inflexor.titleize("man from the boondocks")
"man from the boondocks"
iex> Jungle.Inflexor.titleize("x-men: the last stand")
"X Men: The Last Stand"
iex> Jungle.Inflexor.titleize("TheManWithoutAPast")
"The Man Without A Past"
iex> Jungle.Inflexor.titleize("raiders_of_the_lost_ark")
"Raiders Of The Lost Ark"
iex> Jungle.Inflexor.titleize("string_ending_with_id", [keep_id_suffix: true])
"String Ending With Id"