module Rotor::Inflector

English inflections. The schema's default names come from underscore and pluralize: a table is its model's name in snake_case, plural (BlogPost's is blog_posts), and a foreign key the owner's in snake_case with _id. The rules are few on purpose; write the name when they guess wrong.

/home/runner/work/rotor/rotor/src/inflector.qz:6

Class methods

def self.underscore(name: String) -> String

The snake_case of a class name (BlogPost: blog_post); a namespace is dropped (Admin::User: user).

Rotor::Inflector.underscore("BlogPost") # => "blog_post"
Rotor::Inflector.underscore("Admin::HTTPLog") # => "http_log"

/home/runner/work/rotor/rotor/src/inflector.qz:14

def self.pluralize(word: String) -> String

The plural of a word in snake_case, by its last letters: -y after a consonant makes -ies, -s, -x, -z, -ch and -sh take -es, the rest -s.

Rotor::Inflector.pluralize("post") # => "posts"
Rotor::Inflector.pluralize("category") # => "categories"
Rotor::Inflector.pluralize("address") # => "addresses"

/home/runner/work/rotor/rotor/src/inflector.qz:41

def self.singularize(word: String) -> String

The singular of a plural in snake_case, by its last letters: -ies makes -y, -uses, -sses, -xes, -zes, -ches and -shes drop -es, and another -s (not -ss) is dropped. Words these rules miss (movies, aliases) come out wrong.

Rotor::Inflector.singularize("categories") # => "category"
Rotor::Inflector.singularize("posts") # => "post"

/home/runner/work/rotor/rotor/src/inflector.qz:61

def self.camelize(word: String) -> String

The CamelCase of a snake_case word (blog_post: BlogPost).

Rotor::Inflector.camelize("blog_post") # => "BlogPost"

/home/runner/work/rotor/rotor/src/inflector.qz:79