Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
*.pyc
*.pyc
build/
dist/
inflector.egg-info.DS_Store
.idea/
.DS_Store
inflector.egg-info/
92 changes: 61 additions & 31 deletions README.markdown → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,89 +2,119 @@

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í.
Only English, French 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í.
The French version was implemented by [sblondon](https://github.com/sblondon/pluralizefr).

Apart from converting singulars and plurals, this module also handles necessary string conversion for convention based applications like:
Apart from converting singulars and plurals, this module also handles necessary string
conversion for convention based applications like: *tableize*, *urlize*, and so forth.

Available methods are:

## pluralize(word)
## Requirements

Pluralizes nouns.
* Python 3.x

## singularize(word)
## Getting started

Singularizes nouns.
To install the inflector package, move to *inflector* directory, then run

## conditionalPlural(numer_of_records, word)
$ pip install .

or if necessary

Returns the plural form of a word if first parameter is greater than 1
$ pip3 install .

To work with the inflector, import the `Inflector` and the language support modules:

```{python}
>>> from inflector import Inflector, French, English, Spanish
```

Then, to pluralize, run the following code
```{python}
>>> Inflector(English()).pluralize("matrix")
'matrices'
>>> Inflector(French()).pluralize("cheval")
'chevaux'
>>> Inflector(Spanish()).pluralize("arbol")
'arboles'
```

Lastly, if you want to singularize, run :
```{python}
>>> Inflector(English()).pluralize("matrices")
'matrix'
>>> Inflector(French()).singularize("bijous")
'bijou'
>>> Inflector(Spanish()).singularize("Regímenes")
'Régimen'
```


## Methods available

* **pluralize(word)**
Pluralizes nouns.

* **singularize(word)**
Singularizes nouns.

## titleize(word, uppercase = '')
* **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):

* **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)

* **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 = '')

* **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)

* **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)

* **tableize(class_name)**
Converts a class name to its table name according to rails
naming conventions. Example. Converts "Person" to "people"

## classify(table_name)

* **classify(table_name)**
Converts a table name to its class name according to rails
naming conventions. Example: Converts "people" to "Person"

## ordinalize(number)
*)
* **ordinalize(number)**
Converts number to its ordinal form.
This method converts 13 to 13th, 2 to 2nd ...

## unaccent(text)

* **unaccent(text)**
Transforms a string to its unaccented version.
This might be useful for generating "friendly" URLs

## urlize(text)

* **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)

* **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.
7 changes: 7 additions & 0 deletions inflector/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#coding=utf-8

from .rules.english import English
from .rules.french import French
from .rules.spanish import Spanish

from .inflector import Inflector
Loading