• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

savoirfairelinux / num2words / 6098159229

06 Sep 2023 02:02PM UTC coverage: 97.424% (+4.8%) from 92.579%
6098159229

Pull #492

github

web-flow
Merge 3e39091d0 into f2fb5bc67
Pull Request #492: 2 Issues Potentially Fixed

2978 of 3140 branches covered (0.0%)

Branch coverage included in aggregate %.

3683 of 3696 new or added lines in 84 files covered. (99.65%)

3 existing lines in 1 file now uncovered.

8102 of 8233 relevant lines covered (98.41%)

4.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.29
/num2words/lang_EO.py
1
# -*- coding: utf-8 -*-
2
# Copyright (c) 2021, Savoir-faire Linux inc.  All Rights Reserved.
3

4
# This library is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU Lesser General Public
6
# License as published by the Free Software Foundation; either
7
# version 2.1 of the License, or (at your option) any later version.
8
# This library is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# Lesser General Public License for more details.
12
# You should have received a copy of the GNU Lesser General Public
13
# License along with this library; if not, write to the Free Software
14
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15
# MA 02110-1301 USA
16

17
from __future__ import print_function, unicode_literals
5✔
18

19
from .base import Num2Word_Base
5✔
20

21

22
class Num2Word_EO(Num2Word_Base):
5✔
23
    CURRENCY_FORMS = {
5✔
24
        "EUR": (("eŭro", "eŭroj"), ("centimo", "centimoj")),
25
        "USD": (("dolaro", "dolaroj"), ("cendo", "cendoj")),
26
        "FRF": (("franko", "frankoj"), ("centimo", "centimoj")),
27
        "GBP": (("pundo", "pundoj"), ("penco", "pencoj")),
28
        "CNY": (("juano", "juanoj"), ("feno", "fenoj")),
29
    }
30

31
    GIGA_SUFFIX = "iliardo"
5✔
32
    MEGA_SUFFIX = "iliono"
5✔
33

34
    def set_high_numwords(self, high):
5✔
35
        cap = 3 + 6 * len(high)
5✔
36

37
        for word, n in zip(high, range(cap, 3, -6)):
5✔
38
            if self.GIGA_SUFFIX:
5!
39
                self.cards[10 ** n] = word + self.GIGA_SUFFIX
5✔
40

41
            if self.MEGA_SUFFIX:
5!
42
                self.cards[10 ** (n - 3)] = word + self.MEGA_SUFFIX
5✔
43

44
    def gen_high_numwords(self, units, tens, lows):
5✔
45
        out = [u + t for t in tens for u in units]
5✔
46
        out.reverse()
5✔
47
        return out + lows
5✔
48

49
    def setup(self):
5✔
50
        lows = ["naŭ", "ok", "sep", "ses", "kvin", "kvar", "tr", "b", "m"]
5✔
51
        units = ["", "un", "duo", "tre", "kvatuor",
5✔
52
                 "kvin", "seks", "septen", "okto", "novem"]
53
        tens = ["dek", "vigint", "trigint", "kvadragint", "kvinkvagint",
5✔
54
                "seksagint", "septuagint", "oktogint", "nonagint"]
55

56
        self.high_numwords = ["cent"] + self.gen_high_numwords(units, tens,
5✔
57
                                                               lows)
58

59
        self.negword = "minus "
5✔
60
        self.pointword = "komo"
5✔
61
        self.errmsg_nonnum = u"Sole nombroj povas esti konvertita en vortojn."
5✔
62
        self.errmsg_toobig = (
5✔
63
            u"Tro granda nombro por esti konvertita en vortojn (abs(%s) > %s)."
64
        )
65
        self.exclude_title = ["kaj", "komo", "minus"]
5✔
66
        self.mid_numwords = [(1000, "mil"), (100, "cent"), (90, "naŭdek"),
5✔
67
                             (80, "okdek"), (70, "sepdek"), (60, "sesdek"),
68
                             (50, "kvindek"), (40, "kvardek"), (30, "tridek")]
69
        self.low_numwords = ["dudek", "dek naŭ", "dek ok", "dek sep",
5✔
70
                             "dek ses", "dek kvin", "dek kvar", "dek tri",
71
                             "dek du", "dek unu", "dek", "naŭ", "ok", "sep",
72
                             "ses", "kvin", "kvar", "tri", "du", "unu", "nul"]
73
        self.ords = {
5✔
74
            "unu": "unua",
75
            "du": "dua",
76
            "tri": "tria",
77
            "kvar": "kvara",
78
            "kvin": "kvina",
79
            "ses": "sesa",
80
            "sep": "sepa",
81
            "ok": "oka",
82
            "naŭ": "naŭa",
83
            "dek": "deka"
84
        }
85

86
    def merge(self, curr, next):
5✔
87
        ctext, cnum, ntext, nnum = curr + next
5✔
88
        if cnum == 1 and nnum < 1000000:
5✔
89
            return next
5✔
90

91
        if nnum >= 10**6 and cnum > 1:
5✔
92
            return ("%s %sj" % (ctext, ntext), cnum + nnum)
5✔
93

94
        if nnum == 100:
5✔
95
            return ("%s%s" % (ctext, ntext), cnum + nnum)
5✔
96

97
        return ("%s %s" % (ctext, ntext), cnum + nnum)
5✔
98

99
    def to_ordinal(self, value):
5✔
100
        self.verify_ordinal(value)
5✔
101
        word = self.to_cardinal(value)
5✔
102
        for src, repl in self.ords.items():
5✔
103
            if word.endswith(src):
5✔
104
                word = word[:-len(src)] + repl
5✔
105
                return word
5✔
106

107
        if word.endswith("o"):
5✔
108
            word = word[:-1] + "a"
5✔
109
        elif word.endswith("oj"):
5!
NEW
110
            word = word[:-2] + "a"
×
111
        else:
112
            word = word + "a"
5✔
113
        return word
5✔
114

115
    def to_ordinal_num(self, value):
5✔
116
        self.verify_ordinal(value)
5✔
117
        out = str(value)
5✔
118
        out += "a"
5✔
119
        return out
5✔
120

121
    def to_currency(self, val, currency="EUR", cents=True, separator=" kaj",
5✔
122
                    adjective=False):
123
        result = super(Num2Word_EO, self).to_currency(
5✔
124
            val, currency=currency, cents=cents, separator=separator,
125
            adjective=adjective)
126
        return result
5✔
127

128
    def pluralize(self, n, forms):
5✔
129
        form = 0 if n <= 1 else 1
5✔
130
        return forms[form]
5✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc