-
Notifications
You must be signed in to change notification settings - Fork 0
/
units.py
75 lines (68 loc) · 1.57 KB
/
units.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import enum
import numbers
class Unit(enum.Enum):
Meters = 0
Centimeters = 1
Inches = 2
Foot = 3
Yard = 4
def __eq__(self, __o):
if self.__class__ is __o.__class__:
return self == __o
try:
return self.value == __o.value
except:
pass
try:
if isinstance(__o, numbers.Real):
return self.value == __o
if isinstance(__o, str):
return self.name == __o
except:
pass
return TypeError
def get_cm_multiplier(target):
conversion = {
'Meters': 0.01,
'Centimeters': 1,
'Inches': 0.393701,
'Foot': 0.0328084,
'Yard': 0.0109361
}
return conversion[target]
def get_m_multiplier(target):
conversion = {
'Meters': 1,
'Centimeters': 100,
'Inches': 39.3701,
'Foot': 3.28084,
'Yard': 1.09361
}
return conversion[target]
def get_in_multiplier(target):
conversion = {
'Meters': 0.0254,
'Centimeters': 2.54,
'Inches': 1,
'Foot': 0.0833333,
'Yard': 0.0277778
}
return conversion[target]
def get_ft_multiplier(target):
conversion = {
'Meters': 0.3048,
'Centimeters': 30.48,
'Inches': 12,
'Foot': 1,
'Yard': 0.333333
}
return conversion[target]
def get_yrd_multiplier(target):
conversion = {
'Meters': 0.9144,
'Centimeters': 91.44,
'Inches': 36,
'Foot': 3,
'Yard': 1
}
return conversion[target]