Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.
Merged
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
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ matrix:
python: "2.7"
- env: TOXENV=py27-twisted15
python: "2.7"
- env: TOXENV=py35-twisted15
- env: TOXENV=py27-twisted16
python: "2.7"
- env: TOXENV=py35-twisted16
python: "3.5"
- env: TOXENV=pypy-twisted12
python: "pypy"
Expand All @@ -21,11 +23,12 @@ matrix:
python: "pypy"
- env: TOXENV=pypy-twisted15
python: "pypy"
- env: TOXENV=pypy3-twisted15
- env: TOXENV=pypy-twisted16
python: "pypy"
- env: TOXENV=pypy3-twisted16
python: "pypy3"
allow_failures:
- env: TOXENV=py35-twisted15
- env: TOXENV=pypy3-twisted15
- env: TOXENV=pypy3-twisted16

install:
- pip install tox coveralls pep8 pyflakes
Expand Down
260 changes: 130 additions & 130 deletions BermiInflector/Inflector.py
Original file line number Diff line number Diff line change
@@ -1,130 +1,130 @@
#!/usr/bin/env python
# Copyright (c) 2006 Bermi Ferrer Martinez
#
# bermi a-t bermilabs - com
# See the end of this file for the free software, open source license (BSD-style).
import re
from Rules.English import English
from Rules.Spanish import Spanish
class Inflector :
"""
Inflector for pluralizing and singularizing nouns.
It provides methods for helping on creating programs
based on naming conventions like on Ruby on Rails.
"""
def __init__( self, Inflector = English ) :
assert callable(Inflector), "Inflector should be a callable obj"
self.Inflector = apply(Inflector);
def pluralize(self, word) :
'''Pluralizes nouns.'''
return self.Inflector.pluralize(word)
def singularize(self, word) :
'''Singularizes nouns.'''
return self.Inflector.singularize(word)
def conditionalPlural(self, numer_of_records, word) :
'''Returns the plural form of a word if first parameter is greater than 1'''
return self.Inflector.conditionalPlural(numer_of_records, word)
def titleize(self, 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.'''
return self.Inflector.titleize(word, uppercase)
def camelize(self, 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"'''
return self.Inflector.camelize(word)
def underscore(self, 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.'''
return self.Inflector.underscore(word)
def humanize(self, 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.'''
return self.Inflector.humanize(word, uppercase)
def variablize(self, 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)
def tableize(self, class_name) :
''' Converts a class name to its table name according to rails
naming conventions. Example. Converts "Person" to "people" '''
return self.Inflector.tableize(class_name)
def classify(self, table_name) :
'''Converts a table name to its class name according to rails
naming conventions. Example: Converts "people" to "Person" '''
return self.Inflector.classify(table_name)
def ordinalize(self, number) :
'''Converts number to its ordinal form.
This method converts 13 to 13th, 2 to 2nd ...'''
return self.Inflector.ordinalize(number)
def unaccent(self, text) :
'''Transforms a string to its unaccented version.
This might be useful for generating "friendly" URLs'''
return self.Inflector.unaccent(text)
def urlize(self, text) :
'''Transform a string its unaccented and underscored
version ready to be inserted in friendly URLs'''
return self.Inflector.urlize(text)
def demodulize(self, module_name) :
return self.Inflector.demodulize(module_name)
def modulize(self, module_description) :
return self.Inflector.modulize(module_description)
def foreignKey(self, 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.'''
return self.Inflector.foreignKey(class_name, separate_class_name_and_id_with_underscore)
# Copyright (c) 2006 Bermi Ferrer Martinez
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software to deal in this software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of this software, and to permit
# persons to whom this software is furnished to do so, subject to the following
# condition:
#
# THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THIS SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THIS SOFTWARE.
#!/usr/bin/env python

# Copyright (c) 2006 Bermi Ferrer Martinez
#
# bermi a-t bermilabs - com
# See the end of this file for the free software, open source license (BSD-style).

from __future__ import absolute_import
import re
from .Rules.English import English

class Inflector :
"""
Inflector for pluralizing and singularizing nouns.

It provides methods for helping on creating programs
based on naming conventions like on Ruby on Rails.
"""

def __init__( self, Inflector = English ) :
assert callable(Inflector), "Inflector should be a callable obj"
self.Inflector = Inflector()

def pluralize(self, word) :
'''Pluralizes nouns.'''
return self.Inflector.pluralize(word)

def singularize(self, word) :
'''Singularizes nouns.'''
return self.Inflector.singularize(word)

def conditionalPlural(self, numer_of_records, word) :
'''Returns the plural form of a word if first parameter is greater than 1'''
return self.Inflector.conditionalPlural(numer_of_records, word)

def titleize(self, 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.'''
return self.Inflector.titleize(word, uppercase)

def camelize(self, 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"'''
return self.Inflector.camelize(word)

def underscore(self, 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.'''
return self.Inflector.underscore(word)

def humanize(self, 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.'''
return self.Inflector.humanize(word, uppercase)


def variablize(self, 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)

def tableize(self, class_name) :
''' Converts a class name to its table name according to rails
naming conventions. Example. Converts "Person" to "people" '''
return self.Inflector.tableize(class_name)

def classify(self, table_name) :
'''Converts a table name to its class name according to rails
naming conventions. Example: Converts "people" to "Person" '''
return self.Inflector.classify(table_name)

def ordinalize(self, number) :
'''Converts number to its ordinal form.
This method converts 13 to 13th, 2 to 2nd ...'''
return self.Inflector.ordinalize(number)


def unaccent(self, text) :
'''Transforms a string to its unaccented version.
This might be useful for generating "friendly" URLs'''
return self.Inflector.unaccent(text)

def urlize(self, text) :
'''Transform a string its unaccented and underscored
version ready to be inserted in friendly URLs'''
return self.Inflector.urlize(text)


def demodulize(self, module_name) :
return self.Inflector.demodulize(module_name)

def modulize(self, module_description) :
return self.Inflector.modulize(module_description)

def foreignKey(self, 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.'''
return self.Inflector.foreignKey(class_name, separate_class_name_and_id_with_underscore)




# Copyright (c) 2006 Bermi Ferrer Martinez
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software to deal in this software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of this software, and to permit
# persons to whom this software is furnished to do so, subject to the following
# condition:
#
# THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THIS SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THIS SOFTWARE.
Loading