-
Notifications
You must be signed in to change notification settings - Fork 0
/
bunny-size.js
83 lines (70 loc) · 1.71 KB
/
bunny-size.js
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
76
77
78
79
80
81
82
83
/**
* Save SomeBunny Bunny Page BunnySize Class
* Author: [email protected]
*/
class BunnySize {
constructor(
minMassLbs,
maxMassLbs,
friendlyName,
key
) {
this._minMassLbs = minMassLbs;
this._maxMassLbs = maxMassLbs;
this._friendlyName = friendlyName;
this._key = key;
return;
}
get name() { return this._friendlyName; }
get key() { return this._key; }
hasSizeKey(
key // String
) {
if (this._key === key) { return true; }
return false;
}
static decode(data) {
return BunnySize.withMass(data)
}
static get SMALL() {
return new BunnySize(
1,
4,
'Small (3 to 4lbs)',
'small'
);
}
static get MEDIUM() {
return new BunnySize(
4,
7,
'Medium (4 to 7lbs)',
'medium'
)
}
static get LARGE() {
return new BunnySize(
7,
30,
'Large (7 to 12lbs)',
'large'
)
}
static withKey(
key // String
) {
if (key === 'small') { return BunnySize.SMALL; }
if (key === 'medium') { return BunnySize.MEDIUM; }
if (key === 'large') { return BunnySize.LARGE; }
throw Error('Unknown bunny size key ' + key);
}
static withMass(
mass // Integer pounds
) {
if (mass < 1) { return null; }
if (mass >= 1 && mass < 4) { return BunnySize.SMALL; }
if (mass >= 4 && mass < 7) { return BunnySize.MEDIUM; }
if (mass >= 7) { return BunnySize.LARGE; }
throw Error('Bunny mass out of bounds ' + mass);
}
}