module Wordsmith::Inflector
Extended Modules
Defined in:
wordsmith/inflector/inflections.crwordsmith/inflector/methods.cr
Instance Method Summary
-
#camelize(term, uppercase_first_letter = true)
Convert a given word to the camel-case version of that word.
-
#classify(table_name)
Convert a given table name to the class name for that table.
-
#dasherize(underscored_word)
Convert a given underscore-separated word to the same word, separated by dashes.
-
#deconstantize(path)
Remove any trailing constants from the provided path.
-
#demodulize(path)
Remove leading modules from a provided class name path.
-
#foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
Determine the foreign key representation of a given class name.
-
#humanize(lower_case_and_underscored_word, capitalize = true, keep_id_suffix = false)
Convert a given word to the human-friendly version of that word.
-
#inflections
Return the current set of stored inflection logic.
-
#ordinal(number)
Determine the ordinal suffix for a given number.
-
#ordinalize(number)
Given a number, return the number with the correct ordinal suffix.
-
#parameterize(content : String, separator : String | Nil = "-", preserve_case : Bool = false)
Convert the given string to a parameter-friendly version.
-
#pluralize(word)
Given a word, return the plural version of that word.
-
#singularize(word)
Given a word, return the singular version of that word.
-
#tableize(class_name)
Convert a given class name to the database table name for that class.
-
#titleize(word, keep_id_suffix = false)
Convert a given word to the titleized version of that word, which generally means each word is capitalized.
-
#underscore(camel_cased_word)
Convert a given camel-case word to the underscored version of that word.
-
#upcase_first(string)
Capitalize the first letter of a given word.
Instance Method Detail
Convert a given word to the camel-case version of that word.
Optionally, a second parameter can be provided that controls whether or not the first letter is capitalized.
Examples:
Wordsmith::Inflector.camelize("application_controller") # => "ApplicationController"
Wordsmith::Inflector.camelize("application_controller", uppercase_first_letter: false) # => "applicationController"
Convert a given table name to the class name for that table.
Examples:
Wordsmith::Inflector.classify("users") # => "User"
Wordsmith::Inflector.classify("people") # => "Person"
Wordsmith::Inflector.classify("schema.users") # => "User"
Wordsmith::Inflector.classify("schema.public.users") # => "User"
Convert a given underscore-separated word to the same word, separated by dashes.
Example:
Wordsmith::Inflector.dasherize("post_office") # => "post-office"
Remove any trailing constants from the provided path.
Example:
Wordsmith::Inflector.deconstantize("Helpers::Mixins::User::FREE_TIER_COMMENTS") # => "Helpers::Mixins::User"
Remove leading modules from a provided class name path.
Example:
Wordsmith::Inflector.demodulize("Helpers::Mixins::User") # => "User"
Determine the foreign key representation of a given class name.
Example:
Wordsmith::Inflector.foreign_key("Person") # => "person_id"
Convert a given word to the human-friendly version of that word.
Capitalization and whether or not to retain an _id
suffix can be controlled with optional parameters.
Examples:
Wordsmith::Inflector.humanize("employee_id") # => "Employee"
Wordsmith::Inflector.humanize("employee_id", capitalize: false) # => "employee"
Wordsmith::Inflector.humanize("employee_id", keep_id_suffix: true) # => "Employee id"
Determine the ordinal suffix for a given number.
Example:
Wordsmith::Inflector.ordinal(1) # => "st"
Wordsmith::Inflector.ordinal(2) # => "nd"
Wordsmith::Inflector.ordinal(3) # => "rd"
Wordsmith::Inflector.ordinal(4) # => "th"
Given a number, return the number with the correct ordinal suffix.
Example:
Wordsmith::Inflector.ordinalize(1) # => "1st"
Wordsmith::Inflector.ordinalize(2) # => "2nd"
Wordsmith::Inflector.ordinalize(3) # => "3rd"
Wordsmith::Inflector.ordinalize(4) # => "4th"
Convert the given string to a parameter-friendly version.
The used separator and whether or not to preserve the original object case can be controlled through optional parameters.
Examples:
Wordsmith::Inflector.parameterize("Admin/product") # => "admin-product"
Wordsmith::Inflector.parameterize("Admin::Product", separator: "_") # => "admin_product"
Wordsmith::Inflector.parameterize("Admin::Product", preserve_case: true) # => "Admin-Product"
Given a word, return the plural version of that word.
Example:
Wordsmith::Inflector.pluralize("sandal") # => "sandals"
Wordsmith::Inflector.pluralize("person") # => "people"
Wordsmith::Inflector.pluralize("people") # => "people"
Given a word, return the singular version of that word.
Example:
Wordsmith::Inflector.singularize("sandals") # => "sandal"
Wordsmith::Inflector.singularize("people") # => "person"
Wordsmith::Inflector.singularize("person") # => "person"
Convert a given class name to the database table name for that class.
Examples:
Wordsmith::Inflector.tableize("User") # => "users"
Wordsmith::Inflector.tableize("Person") # => "people"
Convert a given word to the titleized version of that word, which generally means each word is capitalized.
Example:
Wordsmith::Inflector.titleize("amazon web services") # => "Amazon Web Services"
Convert a given camel-case word to the underscored version of that word.
Example:
Wordsmith::Inflector.underscore("ApplicationController") # => "application_controller"
Capitalize the first letter of a given word.
Example:
Wordsmith::Inflector.upcase_first("lucky") # => "Lucky"