#inflector #pluralize #snake #inflection #camel

ruby_inflector

Adds String based inflections for Rust. Snake, kebab, camel, sentence, class, title and table cases as well as ordinalize, deordinalize, demodulize, foreign key, and pluralize/singularize are supported as both traits and pure functions acting on String types. Intended to emulate the behavior of ActiveSupport::Inflector in Ruby as closely as possible. https://api.rubyonrails.org/classes/ActiveSupport/Inflector.html

6 releases

0.0.10 Jun 24, 2023
0.0.9 Jun 24, 2023

#499 in Text processing

Download history 261/week @ 2024-07-20 488/week @ 2024-07-27 519/week @ 2024-08-03 645/week @ 2024-08-10 653/week @ 2024-08-17 848/week @ 2024-08-24 416/week @ 2024-08-31 563/week @ 2024-09-07 464/week @ 2024-09-14 582/week @ 2024-09-21 655/week @ 2024-09-28 626/week @ 2024-10-05 646/week @ 2024-10-12 451/week @ 2024-10-19 713/week @ 2024-10-26 715/week @ 2024-11-02

2,605 downloads per month
Used in pks

BSD-2-Clause

125KB
3K SLoC

Rust Inflector

This project is forked from https://github.com/chrislearn/cruet.

The intent of this library is to emulate https://api.rubyonrails.org/classes/ActiveSupport/Inflector.html as closely as possible to allow for rust implementations of ruby tools.

CI Audit

Adds String based inflections for Rust. Snake, kebab, train, camel, sentence, class, and title cases as well as ordinalize, deordinalize, demodulize, deconstantize, foreign key, table case, and pluralize/singularize are supported as both traits and pure functions acting on &str and String types.


Documentation:

Documentation can be found here at the README or via rust docs below.

Rust docs with examples


Installation:

As a crate

[dependencies]
ruby_inflector = "*"

Compile yourself:

  1. Install Rust and cargo
  2. git clone https://github.com/alexevanczuk/ruby_inflector
  3. Library: cd ruby_inflector && cargo build --release --lib
  4. You can find the library in target/release

Usage / Example:

// to use methods like String.to_lower_case();
use ruby_inflector::Inflector;
fn main() {
  let camel_case_string: String = "some_string".to_camel_case();
}

Or

// to use methods like to_snake_case(&str);
use ruby_inflector;

// use ruby_inflector::to_class_case;
// use ruby_inflector::is_class_case;

// use ruby_inflector::to_camel_case;
// use ruby_inflector::is_camel_case;

// use ruby_inflector::to_pascal_case;
// use ruby_inflector::is_pascal_case;

// use ruby_inflector::to_screamingsnake_case;
// use ruby_inflector::is_screamingsnake_case;

// use ruby_inflector::to_snake_case;
// use ruby_inflector::is_snake_case;

// use ruby_inflector::to_kebab_case;
// use ruby_inflector::is_kebab_case;

// use ruby_inflector::to_train_case;
// use ruby_inflector::is_train_case;

// use ruby_inflector::to_sentence_case;
// use ruby_inflector::is_sentence_case;

// use ruby_inflector::to_title_case;
// use ruby_inflector::is_title_case;

// use ruby_inflector::to_table_case;
// use ruby_inflector::is_table_case;

// use ruby_inflector::ordinalize;
// use ruby_inflector::deordinalize;

// use ruby_inflector::to_foreign_key;
// use ruby_inflector::is_foreign_key;

// use ruby_inflector::demodulize;
// use ruby_inflector::deconstantize;

// use ruby_inflector::to_plural;
// use ruby_inflector::to_singular;
fn main() {
  let camel_case_string: String = to_camel_case("some_string");
}

Contributing

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Dependencies

~2.1–3MB
~54K SLoC