Exemple #1
0
def numerals(nNumero, lFemenino=0, andword='con', money=False, currency_word='bolívar', cents_word='céntimo'):
    """
    numerals(nNumero, lFemenino) --> cLiteral

    Convierte el número a una cadena literal de caracteres
    P.e.:       201     -->   "doscientos uno"
    1111     -->   "mil ciento once"

    <nNumero>       Número a convertir
    <lFemenino>     = 'true' si el Literal es femenino
    P.e.:   201     -->    "doscientas una"
    """
    # Nos aseguramos del tipo de <nNumero>
    # se podría adaptar para usar otros tipos (pe: float)

    #nNumero = long(nNumero)

    if nNumero<0:       cRes = "menos "+_numerals(-nNumero,lFemenino)
    elif nNumero==0:    cRes = "cero"
    if type(nNumero) == float:
        float_number = str(nNumero).split('.')
        nNumero = int(float_number[0])
        if nNumero == 0: cRes = "cero"
        else: cRes = _numerals(nNumero,lFemenino)
        dec = int(float_number[1])            
        if money:
            currency_word = currency_word.strip()
            cents_word = cents_word.strip()
            inflector_obj = Inflector(Inflector=Spanish)
            if nNumero != 1:
                currency_word = inflector_obj.pluralize(currency_word)
            if cRes[-8:] == 'millones': cRes += ' de'
            cRes += ' '+currency_word
        if dec != 0: 
            cRes += ' '+andword.strip()+' '+_numerals(dec,lFemenino)
        if money:
            if dec != 1:
                cents_word = inflector_obj.pluralize(cents_word)
            if dec != 0: cRes += ' '+cents_word
    else:               
        if type(nNumero) == str: nNumero = long(nNumero)
        if nNumero==0: cRes = "cero"
        else: cRes = _numerals(nNumero,lFemenino)
        if money:
            currency_word = currency_word.strip()
            inflector_obj = Inflector(Inflector=Spanish)
            if nNumero != 1:
                currency_word = inflector_obj.pluralize(currency_word)
            if cRes[-8:] == 'millones': cRes += ' de'
            cRes += ' '+currency_word

    # Excepciones a considerar
    if not lFemenino and nNumero%10 == 1 and nNumero%100!=11 and not money:
        cRes += "o"

    return cRes.decode('utf-8')
Exemple #2
0
class Resource(object):
    def __init__(self, json_str):
        self.json = json_str
        self.inflector = Inflector(English)

    def get_method(self, name):
        name_dict = dict((m["name"], m) for m in self.json.get('methods', []))
        return Method(name_dict[name], self.name())

    def has_method(self, name):
        return name in [m['name'] for m in self.json.get('methods', [])]

    def methods(self):
        return [Method(m, self.name()) for m in self.json.get('methods', [])]

    def name(self, safe=False, title=False):
        name = self.inflector.singularize(self.json['name']).lower()
        if title:
            name = name.title()
        return name.replace(" ", "") if safe else name
Exemple #3
0
class Resource(object):

    def __init__(self, json_str):
        self.json = json_str
        self.inflector = Inflector(English)

    def get_method(self, name):
        name_dict = dict((m["name"], m) for m in self.json.get('methods', []))
        return Method(name_dict[name], self.name())

    def has_method(self, name):
        return name in [m['name'] for m in self.json.get('methods', [])]

    def methods(self):
        return [Method(m, self.name()) for m in self.json.get('methods', [])]

    def name(self, safe=False, title=False):
        name = self.inflector.singularize(self.json['name']).lower()
        if title:
            name = name.title()
        return name.replace(" ", "") if safe else name
Exemple #4
0
 def __init__(self, json_str):
     self.json = json_str
     self.inflector = Inflector(English)
Exemple #5
0
 def __init__(self, json_str):
     self.json = json_str
     self.inflector = Inflector(English)