Skip to main content

Inflector for Python

Project description

# 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Inflector-3.0.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Inflector-3.0.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file Inflector-3.0.1.tar.gz.

File metadata

  • Download URL: Inflector-3.0.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.5.6

File hashes

Hashes for Inflector-3.0.1.tar.gz
Algorithm Hash digest
SHA256 21add07f255a45ef83523ea73747b0651a1d680c79d0853009c4abff218d4d10
MD5 90b24329f831c60f46f4d9f0ac11e835
BLAKE2b-256 1b6d53be827fd799ec5e6c6833f1afb379cfc1066816566b2a93e6ef4f54fc62

See more details on using hashes here.

File details

Details for the file Inflector-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: Inflector-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for Inflector-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b77a1863df8b86a70bb2a73ffa84ad579198f4cb11028561ea2e53c0845b472
MD5 428e8e02bb93d7a07b8d4eae31f6c825
BLAKE2b-256 e0ab68258da045def3fd58847c9e7c6125ed35b857e0be80349d58685c4742a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page