module

Wordsmith::Inflector

Instance methods

camelize(term : String, uppercase_first_letter : Bool = true) : String

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"
Source
camelize(io : IO, term : String, uppercase_first_letter : Bool = true) : Nil

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"
Source
classify(io : IO, table_name : String | Symbol) : Nil

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"
Source
classify(table_name : String | Symbol) : String

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"
Source
dasherize(io : IO, underscored_word : String) : Nil

Convert a given underscore-separated word to the same word, separated by dashes.

Example:

Wordsmith::Inflector.dasherize("post_office") # => "post-office"
Source
dasherize(underscored_word : String) : String

Convert a given underscore-separated word to the same word, separated by dashes.

Example:

Wordsmith::Inflector.dasherize("post_office") # => "post-office"
Source
deconstantize(io : IO, path : String) : Nil

Remove any trailing constants from the provided path.

Example:

Wordsmith::Inflector.deconstantize("Helpers::Mixins::User::FREE_TIER_COMMENTS") # => "Helpers::Mixins::User"
Source
deconstantize(path : String) : String

Remove any trailing constants from the provided path.

Example:

Wordsmith::Inflector.deconstantize("Helpers::Mixins::User::FREE_TIER_COMMENTS") # => "Helpers::Mixins::User"
Source
demodulize(io : IO, path : String) : Nil

Remove leading modules from a provided class name path.

Example:

Wordsmith::Inflector.demodulize("Helpers::Mixins::User") # => "User"
Source
demodulize(path : String) : String

Remove leading modules from a provided class name path.

Example:

Wordsmith::Inflector.demodulize("Helpers::Mixins::User") # => "User"
Source
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.

Example:

Wordsmith::Inflector.foreign_key("Person") # => "person_id"
Source
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.

Example:

Wordsmith::Inflector.foreign_key("Person") # => "person_id"
Source
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.

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"
Source
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.

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"
Source
inflections

Return the current set of stored inflection logic.

Source
ordinal(io : IO, number : Int | String) : Nil

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

Source
ordinal(number : Int | String) : String

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

Source
ordinalize(io : IO, number : Int | String) : Nil

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

Source
ordinalize(number : Int | String) : String

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

Source
parameterize(content : String, separator : String | Nil = "-", preserve_case : Bool = false) : String

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"
Source
parameterize(io : IO, content : String, separator : String | Nil = "-", preserve_case : Bool = false) : Nil

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"
Source
pluralize(io : IO, word : String) : Nil

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"
Source
pluralize(word : String) : String

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"
Source
singularize(io : IO, word : String) : Nil

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"
Source
singularize(word : String) : String

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"
Source
tableize(io : IO, class_name : String) : Nil

Convert a given class name to the database table name for that class.

Examples:

Wordsmith::Inflector.tableize("User")   # => "users"
Wordsmith::Inflector.tableize("Person") # => "people"
Source
tableize(class_name : String) : String

Convert a given class name to the database table name for that class.

Examples:

Wordsmith::Inflector.tableize("User")   # => "users"
Wordsmith::Inflector.tableize("Person") # => "people"
Source
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.

Example:

Wordsmith::Inflector.titleize("amazon web services") # => "Amazon Web Services"
Source
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.

Example:

Wordsmith::Inflector.titleize("amazon web services") # => "Amazon Web Services"
Source
underscore(io : IO, camel_cased_word : String) : Nil

Convert a given camel-case word to the underscored version of that word.

Example:

Wordsmith::Inflector.underscore("ApplicationController") # => "application_controller"
Source
underscore(camel_cased_word : String) : String

Convert a given camel-case word to the underscored version of that word.

Example:

Wordsmith::Inflector.underscore("ApplicationController") # => "application_controller"
Source
upcase_first(io : IO, string : String) : Nil

Capitalize the first letter of a given word.

Example:

Wordsmith::Inflector.upcase_first("lucky") # => "Lucky"
Source
upcase_first(string : String) : String

Capitalize the first letter of a given word.

Example:

Wordsmith::Inflector.upcase_first("lucky") # => "Lucky"
Source

Nested types