Giter Site home page Giter Site logo

aman-clement / inflector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ixmatus/inflector

0.0 0.0 0.0 30 KB

inflector inflects and uninflects words. It also transforms between camelCase and under_score strings.

License: BSD 3-Clause "New" or "Revised" License

Python 99.73% Makefile 0.27%

inflector's Introduction

inflector Downloads Last Month

Inflector for Python

The Inflector is used for getting the plural and singular form of nouns. This piece of code helps on creating code that favors convention over configuration.

Only English and Spanish nouns are supported. The English version is a port of Ruby on Rails Inflector, while the Spanish Version has been developed from scratch with the help of Carles Sadurní.

Apart from converting singulars and plurals, this module also handles necessary string conversion for convention based applications like:

Available methods are:

pluralize(word)

Pluralizes nouns.

singularize(word)

Singularizes nouns.

conditionalPlural(numer_of_records, word)

Returns the plural form of a word if first parameter is greater than 1

titleize(word, uppercase = '')

Converts an underscored or CamelCase word into a sentence. The titleize function converts text like "WelcomePage", "welcome_page" or "welcome page" to this "Welcome Page". If the "uppercase" parameter is set to 'first' it will only capitalize the first character of the title.

camelize(word):

Returns given word as CamelCased Converts a word like "send_email" to "SendEmail". It will remove non alphanumeric character from the word, so "who's online" will be converted to "WhoSOnline"

underscore(word)

Converts a word "into_it_s_underscored_version" Convert any "CamelCased" or "ordinary Word" into an "underscored_word". This can be really useful for creating friendly URLs.

humanize(word, uppercase = '')

Returns a human-readable string from word Returns a human-readable string from word, by replacing underscores with a space, and by upper-casing the initial character by default. If you need to uppercase all the words you just have to pass 'all' as a second parameter.

variablize(word)

Same as camelize but first char is lowercased Converts a word like "send_email" to "sendEmail". It will remove non alphanumeric character from the word, so "who's online" will be converted to "whoSOnline" return self.Inflector.variablize(word)

tableize(class_name)

Converts a class name to its table name according to rails naming conventions. Example. Converts "Person" to "people"

classify(table_name)

Converts a table name to its class name according to rails naming conventions. Example: Converts "people" to "Person"

ordinalize(number)

Converts number to its ordinal form. This method converts 13 to 13th, 2 to 2nd ...

unaccent(text)

Transforms a string to its unaccented version. This might be useful for generating "friendly" URLs

urlize(text)

Transform a string its unaccented and underscored version ready to be inserted in friendly URLs

foreignKey(class_name, separate_class_name_and_id_with_underscore = 1)

Returns class_name in underscored form, with "_id" tacked on at the end. This is for use in dealing with the database.

inflector's People

Contributors

ixmatus avatar aman-clement avatar darkman66 avatar jairhenrique avatar lowks avatar matthewmcintire avatar tjnycum avatar yukihiko-shinoda avatar

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.