module
Wordsmith::Inflector
Extended Modules
Defined in:
wordsmith/inflector/inflections.crwordsmith/inflector/methods.cr
Instance Method Summary
-
#camelize(term : String, uppercase_first_letter : Bool = true) : String
Convert a given word to the camel-case version of that word.
-
#camelize(io : IO, term : String, uppercase_first_letter : Bool = true) : Nil
Convert a given word to the camel-case version of that word.
-
#classify(io : IO, table_name : String | Symbol) : Nil
Convert a given table name to the class name for that table.
-
#classify(table_name : String | Symbol) : String
Convert a given table name to the class name for that table.
-
#dasherize(io : IO, underscored_word : String) : Nil
Convert a given underscore-separated word to the same word, separated by dashes.
-
#dasherize(underscored_word : String) : String
Convert a given underscore-separated word to the same word, separated by dashes.
-
#deconstantize(io : IO, path : String) : Nil
Remove any trailing constants from the provided path.
-
#deconstantize(path : String) : String
Remove any trailing constants from the provided path.
-
#demodulize(io : IO, path : String) : Nil
Remove leading modules from a provided class name path.
-
#demodulize(path : String) : String
Remove leading modules from a provided class name path.
-
#foreign_key(class_name : String, separate_class_name_and_id_with_underscore : Bool = true) : String
Determine the foreign key representation of a given class name.
-
#foreign_key(io : IO, class_name : String, separate_class_name_and_id_with_underscore : Bool = true) : Nil
Determine the foreign key representation of a given class name.
-
#humanize(lower_case_and_underscored_word : String, capitalize : Bool = true, keep_id_suffix : Bool = false) : String
Convert a given word to the human-friendly version of that word.
-
#humanize(io : IO, lower_case_and_underscored_word : String, capitalize : Bool = true, keep_id_suffix : Bool = false) : Nil
Convert a given word to the human-friendly version of that word.
-
#inflections : Inflections
Return the current set of stored inflection logic.
-
#ordinal(io : IO, number : Int | String) : Nil
Determine the ordinal suffix for a given number.
-
#ordinal(number : Int | String) : String
Determine the ordinal suffix for a given number.
-
#ordinalize(io : IO, number : Int | String) : Nil
Given a number, return the number with the correct ordinal suffix.
-
#ordinalize(number : Int | String) : String
Given a number, return the number with the correct ordinal suffix.
-
#parameterize(content : String, separator : String | Nil = "-", preserve_case : Bool = false) : String
Convert the given string to a parameter-friendly version.
-
#parameterize(io : IO, content : String, separator : String | Nil = "-", preserve_case : Bool = false) : Nil
Convert the given string to a parameter-friendly version.
-
#pluralize(io : IO, word : String) : Nil
Given an IO and a word, it appends the plural version of that word to the IO.
-
#pluralize(word : String) : String
Given a word, return the plural version of that word.
-
#singularize(io : IO, word : String) : Nil
Given an IO and a word, it appends the singular version of that word to the IO.
-
#singularize(word : String) : String
Given a word, return the singular version of that word.
-
#tableize(io : IO, class_name : String) : Nil
Convert a given class name to the database table name for that class.
-
#tableize(class_name : String) : String
Convert a given class name to the database table name for that class.
-
#titleize(word : String, keep_id_suffix : Bool = false) : String
Convert a given word to the titleized version of that word, which generally means each word is capitalized.
-
#titleize(io : IO, word : String, keep_id_suffix : Bool = false) : Nil
Convert a given word to the titleized version of that word, which generally means each word is capitalized.
-
#underscore(io : IO, camel_cased_word : String) : Nil
Convert a given camel-case word to the underscored version of that word.
-
#underscore(camel_cased_word : String) : String
Convert a given camel-case word to the underscored version of that word.
-
#upcase_first(io : IO, string : String) : Nil
Capitalize the first letter of a given word.
-
#upcase_first(string : String) : 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 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 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"
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 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"
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"
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"
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"
TODO This should only take an Int
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"
TODO This should only take an Int
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"
TODO This should only take an Int
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"
TODO This should only take an Int
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"
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 an IO and a word, it appends the plural version of that word to the IO.
Example:
io = IO::Memory.new
Wordsmith::Inflector.pluralize(io, "person")
io.to_s # => "people"
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 an IO and a word, it appends the singular version of that word to the IO.
Example:
io = IO::Memory.new
Wordsmith::Inflector.singularize(io, "people")
io.to_s # => "person"
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 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 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"
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"
Capitalize the first letter of a given word.
Example:
Wordsmith::Inflector.upcase_first("lucky") # => "Lucky"