class Dry::Inflector

Overview

dry-inflector

@since 0.1.0

Defined in:

dry/inflector.cr
dry/inflector/acronyms.cr
dry/inflector/inflections.cr
dry/inflector/inflections/defaults.cr
dry/inflector/rules.cr
dry/inflector/version.cr

Constant Summary

VERSION = "1.0.0"

@since 0.1.0

Constructors

Instance Method Summary

Constructor Detail

def self.new(&blk : Inflections -> _) #

Instantiate the inflector

@param blk [Proc] an optional block to specify custom inflection rules @yieldparam [Dry::Inflector::Inflections] the inflection rules

@return [Dry::Inflector] the inflector

@since 0.1.0

@example Basic usage require "dry/inflector"

inflector = Dry::Inflector.new

@example Custom inflection rules require "dry/inflector"

inflector = Dry::Inflector.new do |inflections| inflections.plural "virus", "viruses" # specify a rule for #pluralize inflections.singular "thieves", "thief" # specify a rule for #singularize inflections.uncountable "dry-inflector" # add an exception for an uncountable word end


[View source]
def self.new #

[View source]

Instance Method Detail

def camelize(input) #

[View source]
def camelize_lower(input) #

Lower camelize a string

@param input [String,Symbol] the input @return [String] the lower camelized string

@since 0.1.3

@example require "dry/inflector"

inflector = Dry::Inflector.new inflector.camelize_lower("data_mapper") # => "dataMapper"


[View source]
def camelize_upper(input) #

Upper camelize a string

@param input [String,Symbol] the input @return [String] the upper camelized string

@since 0.1.3

@example require "dry/inflector"

inflector = Dry::Inflector.new inflector.camelize_upper("data_mapper") # => "DataMapper" inflector.camelize_upper("dry/inflector") # => "Dry::Inflector"


[View source]
def classify(input) #

Classify a string

@param input [String,Symbol] the input @return [String] the classified string

@since 0.1.0

@example require "dry/inflector"

inflector = Dry::Inflector.new inflector.classify("books") # => "Book"


[View source]
def constantize(input) #

Find a constant with the name specified in the argument string

The name is assumed to be the one of a top-level constant, constant scope of caller is ignored

@param input [String,Symbol] the input @return [Class, Module] the class or module

@since 0.1.0

@example require "dry/inflector"

inflector = Dry::Inflector.new inflector.constantize("Module") # => Module inflector.constantize("Dry::Inflector") # => Dry::Inflector


[View source]
def dasherize(input) #

Dasherize a string

@param input [String,Symbol] the input @return [String] the dasherized string

@since 0.1.0

@example require "dry/inflector"

inflector = Dry::Inflector.new inflector.dasherize("dry_inflector") # => "dry-inflector"


[View source]
def demodulize(input) #

Demodulize a string

@param input [String,Symbol] the input @return [String] the demodulized string

@since 0.1.0

@example require "dry/inflector"

inflector = Dry::Inflector.new inflector.demodulize("Dry::Inflector") # => "Inflector"


[View source]
def foreign_key(input) #

Creates a foreign key name

@param input [String, Symbol] the input @return [String] foreign key

@example require "dry/inflector"

inflector = Dry::Inflector.new inflector.foreign_key("Message") => "message_id"


[View source]
def humanize(input) #

Humanize a string

@param input [String,Symbol] the input @return [String] the humanized string

@since 0.1.0

@example require "dry/inflector"

inflector = Dry::Inflector.new inflector.humanize("dry_inflector") # => "Dry inflector" inflector.humanize("author_id") # => "Author"


[View source]
def inspect #
Description copied from class Object

Returns an unambiguous and information-rich string representation of this object, typically intended for developers.

This method should usually not be overridden. It delegates to #inspect(IO) which can be overridden for custom implementations.

Also see #to_s.


[View source]
def ordinalize(number) #

Ordinalize a number

@param number [Integer] the input @return [String] the ordinalized number

@since 0.1.0

@example require "dry/inflector"

inflector = Dry::Inflector.new inflector.ordinalize(1) # => "1st" inflector.ordinalize(2) # => "2nd" inflector.ordinalize(3) # => "3rd" inflector.ordinalize(10) # => "10th" inflector.ordinalize(23) # => "23rd"


[View source]
def pluralize(input) #

Pluralize a string

@param input [String,Symbol] the input @return [String] the pluralized string

@since 0.1.0

@example require "dry/inflector"

inflector = Dry::Inflector.new inflector.pluralize("book") # => "books" inflector.pluralize("money") # => "money"


[View source]
def singularize(input) #

Singularize a string

@param input [String] the input @return [String] the singularized string

@since 0.1.0

@example require "dry/inflector"

inflector = Dry::Inflector.new inflector.singularize("books") # => "book" inflector.singularize("money") # => "money"


[View source]
def tableize(input) #

Tableize a string

@param input [String,Symbol] the input @return [String] the tableized string

@since 0.1.0

@example require "dry/inflector"

inflector = Dry::Inflector.new inflector.tableize("Book") # => "books"


[View source]
def to_s #

@return [String]

@since 0.2.0 @api public


[View source]
def uncountable?(input) #

Check if the input is an uncountable word

@param input [String] the input @return [TrueClass,FalseClass] the result of the check

@since 0.1.0 @api private


[View source]
def underscore(input) #

Underscore a string

@param input [String,Symbol] the input @return [String] the underscored string

@since 0.1.0

@example require "dry/inflector"

inflector = Dry::Inflector.new inflector.underscore("dry-inflector") # => "dry_inflector"


[View source]