-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacronym.py
executable file
·49 lines (36 loc) · 1.42 KB
/
acronym.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python
"""
CV2GLS
Matt Luckcuck <[email protected]>
Glossary Package Acronym Object
"""
class Acronym(object):
"""Stores an acronym, ensuring that the key is unique """
indexMap = {}
def __init__(self, acronym, description):
self.setKey(acronym.lower().strip("\n").replace("&","and"))
self.acronym=acronym.upper().strip("\n").replace("&","\&")
self.description = description.strip("\n").strip('\"')
def getKey(self):
return self.key
def getAcronym(self):
return self.acronym
def getDescription(self):
return self.description
def setKey(self, key):
""" Sets the key, appending an ordinal number if it already exists """
#if the key already exists...
if key in Acronym.indexMap.keys():
#get the current number of times that key exists...
curKeyindex = Acronym.indexMap[key]
#append that number and append to the key...
self.key = key + str(curKeyindex)
#increment the currnet number of key instances
Acronym.indexMap[key]= curKeyindex+1
#works because the first key is 0, but that isn't printed
else:
Acronym.indexMap[key] = 1
self.key = key
def getGLSLine(self):
glsLine = "\\newacronym{" + self.getKey() + "}{" + self.getAcronym() + "}{" + self.getDescription() + "}\n"
return glsLine