No commit activity in last 3 years
No release in over 3 years
A yet another Ruby library for string inflection.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
~> 10.0
~> 3.0
 Project Readme

StringInflection

A yet another Ruby library for string inflection.

Build Status

Benefits

  • No more Active Support in your Gemfiles/gemspecs only for inflection.
  • A clean way - the Ruby's refinement.

Installation

Add this line to your application's Gemfile:

gem 'string_inflection'

And then execute:

$ bundle

Or install it yourself as:

$ gem install string_inflection

Usage

require "string_inflection"
using StringInflection

'foo bar'.to_camel # 'fooBar'
'foo bar'.to_kebab # 'foo-bar'
'foo bar'.to_pascal # 'FooBar'
'foo bar'.to_snake # 'foo_bar'
'data'.to_singular # 'datum'
'child'.to_plural # 'children'

Upper Case Replacement

With the :up option, #to_singular / #to_plural replaces a string with upper case letters.

'DATA'.to_singular(up: true) # 'DATUM'
'CHILD'.to_plural(up: true) # 'CHILDREN'

Note: :up affects only a replaced substring.

'data'.to_singular(up: true) # 'datUM'
'child'.to_plural(up: true) # 'childREN'

Refinement Modules

For performance improvement, the inflection methods are separated into several modules. Use ones of the modules as needed.

module methods
StringInflection::Cases to_camel, to_kebab, to_pascal, to_snake
StringInflection::Singular to_singular
StringInflection::Plural to_plural
StringInflection all the methods

Special Thanks

The handy database by Kevin Atkinson and other authors is significantly useful to generate irregular singular/plural forms. You can see the license in README.

Release Notes

  • v0.1.2
    • Upper Case Replacement

Authors

mosop - creator, maintainer