-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIECDigitalUnit.php
More file actions
76 lines (67 loc) · 1.94 KB
/
IECDigitalUnit.php
File metadata and controls
76 lines (67 loc) · 1.94 KB
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
<?php
declare(strict_types=1);
namespace Andante\Measurement\Unit\Digital\IEC;
use Andante\Measurement\Contract\DimensionInterface;
use Andante\Measurement\Contract\UnitInterface;
use Andante\Measurement\Dimension\DigitalInformation;
use Andante\Measurement\Unit\SymbolNotation;
use Andante\Measurement\Unit\UnitSystem;
/**
* IEC (binary) Digital Information units.
*
* Uses binary prefixes: kibi (2^10), mebi (2^20), gibi (2^30), tebi (2^40), pebi (2^50)
* Includes both bit-based and byte-based units.
*/
enum IECDigitalUnit implements UnitInterface
{
// Bit-based
case Kibibit;
case Mebibit;
case Gibibit;
case Tebibit;
case Pebibit;
// Byte-based
case Kibibyte;
case Mebibyte;
case Gibibyte;
case Tebibyte;
case Pebibyte;
public function symbol(SymbolNotation $notation = SymbolNotation::Default): string
{
return match ($this) {
self::Kibibit => 'Kib',
self::Mebibit => 'Mib',
self::Gibibit => 'Gib',
self::Tebibit => 'Tib',
self::Pebibit => 'Pib',
self::Kibibyte => 'KiB',
self::Mebibyte => 'MiB',
self::Gibibyte => 'GiB',
self::Tebibyte => 'TiB',
self::Pebibyte => 'PiB',
};
}
public function name(): string
{
return match ($this) {
self::Kibibit => 'kibibit',
self::Mebibit => 'mebibit',
self::Gibibit => 'gibibit',
self::Tebibit => 'tebibit',
self::Pebibit => 'pebibit',
self::Kibibyte => 'kibibyte',
self::Mebibyte => 'mebibyte',
self::Gibibyte => 'gibibyte',
self::Tebibyte => 'tebibyte',
self::Pebibyte => 'pebibyte',
};
}
public function dimension(): DimensionInterface
{
return DigitalInformation::instance();
}
public function system(): UnitSystem
{
return UnitSystem::IEC;
}
}