GithubHelp home page GithubHelp logo

inflector's Introduction

Inflector.erl: Rails Style String Inflection For Erlang

Rails’ ActiveSupport package includes an inflector class. This lets you do things like singularize and pluralize strings, camel case text, etc.

I’m building a framework that lets Rails developers use erlang + mnesia to replace their ruby models and traditional relational DBs (using Hyperactive Resource + Mochiweb). But a key part of interoperating with rails is being able to infer that “Person” is the singular for “People”.

Inflector.erl brings this magic to erlang! Witness the awesome power:

1> inflector:singularize("mice").
"mouse"
2> inflector:titleize("i_love_erlang").
"I Love Erlang"
3> inflector:ordinalize(142).
"142nd"
5> inflector:pluralize("quiz").
"quizzes"
7> inflector:tableize("MyModelModule").
"my_model_modules"

Inflector.erl includes functions for pluralizing, singularizing, camelizing, titleizing,
capitalizing, humanizing, underscoring, dasherizing, tableizing, moduleizing,
foreign_key..isizing? and ordinalizing!

I found it very difficult to implement some functions without regular expressions, so it does require R12B4 of erlang due to the vastly improved regular expression support B4 offers. The majority of the inflections are just standard pattern matching and list manipulation, though.

It also has an eunit test suite embedded, so it requires eunit to compile.. But everyone has eunit, right?

Also, in order to minimize the impact of compiling the regular expressions, Inflector.erl caches all compiled regular expressions.. so I expect performance won’t be a problem but be aware that it does register a process named “re_cache”.

Copyright 2008 Luke Galea - released under MIT License

inflector's People

Contributors

lukegalea avatar

Stargazers

Lysanne Kozey avatar Angus H. avatar Michael Swan avatar Kirill Mokevnin avatar  avatar Tim Watson avatar Michael Mullis avatar  avatar Sébastien Arnaud avatar Andrzej Śliwa avatar Chase James avatar Michael Greene avatar Carlos Brando avatar Dane Jensen avatar

Watchers

 avatar liuzhen avatar  avatar

inflector's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.