1 | <?php namespace Arcanedev\Units\Measures; |
||
13 | class Weight extends UnitMeasure implements WeightContract |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Traits |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | |||
20 | use Calculatable; |
||
21 | |||
22 | /* ----------------------------------------------------------------- |
||
23 | | Constructor |
||
24 | | ----------------------------------------------------------------- |
||
25 | */ |
||
26 | |||
27 | /** |
||
28 | * Weight constructor. |
||
29 | * |
||
30 | * @param float|int $value |
||
31 | * @param string $unit |
||
32 | * @param array $options |
||
33 | */ |
||
34 | 66 | public function __construct($value = 0, $unit = self::KG, array $options = []) |
|
38 | |||
39 | /* ----------------------------------------------------------------- |
||
40 | | Getters & Setters |
||
41 | | ----------------------------------------------------------------- |
||
42 | */ |
||
43 | |||
44 | /** |
||
45 | * Get the default names. |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | 63 | public function defaultNames() |
|
50 | { |
||
51 | 63 | return array_combine(static::units(), [ |
|
52 | 63 | 'ton', |
|
53 | 'kilogram', |
||
54 | 'gram', |
||
55 | 'milligram', |
||
56 | ]); |
||
57 | } |
||
58 | |||
59 | /* ----------------------------------------------------------------- |
||
60 | | Main Methods |
||
61 | | ----------------------------------------------------------------- |
||
62 | */ |
||
63 | |||
64 | /** |
||
65 | * Make a weight instance. |
||
66 | * |
||
67 | * @param float|int $value |
||
68 | * @param string $unit |
||
69 | * @param array $options |
||
70 | * |
||
71 | * @return \Arcanedev\Units\Contracts\Measures\Weight|\Arcanedev\Units\Contracts\UnitMeasure |
||
72 | */ |
||
73 | 24 | public static function make($value = 0, $unit = self::KG, array $options = []) |
|
77 | |||
78 | /* ----------------------------------------------------------------- |
||
79 | | Calculation Methods |
||
80 | | ----------------------------------------------------------------- |
||
81 | */ |
||
82 | |||
83 | /** |
||
84 | * Add the weight. |
||
85 | * |
||
86 | * @param float|int $value |
||
87 | * @param string $unit |
||
88 | * |
||
89 | * @return \Arcanedev\Units\Contracts\Measures\Weight|\Arcanedev\Units\Contracts\UnitMeasure |
||
90 | */ |
||
91 | 6 | public function addWeight($value, $unit = self::KG) |
|
95 | |||
96 | /** |
||
97 | * Sub the weight. |
||
98 | * |
||
99 | * @param float|int $value |
||
100 | * @param string $unit |
||
101 | * |
||
102 | * @return \Arcanedev\Units\Contracts\Measures\Weight|\Arcanedev\Units\Contracts\UnitMeasure |
||
103 | */ |
||
104 | 6 | public function subWeight($value, $unit = self::KG) |
|
108 | |||
109 | /* ----------------------------------------------------------------- |
||
110 | | Other Methods |
||
111 | | ----------------------------------------------------------------- |
||
112 | */ |
||
113 | |||
114 | /** |
||
115 | * Get the weight convert ratio. |
||
116 | * |
||
117 | * @param string $to |
||
118 | * @param string $from |
||
119 | * |
||
120 | * @return double|float|integer |
||
121 | */ |
||
122 | 6 | protected static function getRatio($to, $from) |
|
133 | |||
134 | /** |
||
135 | * Get all the weight ratios. |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | 6 | protected static function getRatios() |
|
153 | } |
||
154 |