1 | <?php namespace Arcanedev\Units\Measures; |
||
13 | class Weight extends UnitMeasure implements WeightContract |
||
14 | { |
||
15 | /* ------------------------------------------------------------------------------------------------ |
||
16 | | Traits |
||
17 | | ------------------------------------------------------------------------------------------------ |
||
18 | */ |
||
19 | use Calculatable; |
||
20 | |||
21 | /* ------------------------------------------------------------------------------------------------ |
||
22 | | Constructor |
||
23 | | ------------------------------------------------------------------------------------------------ |
||
24 | */ |
||
25 | /** |
||
26 | * Weight constructor. |
||
27 | * |
||
28 | * @param float|int $value |
||
29 | * @param string $unit |
||
30 | * @param array $options |
||
31 | */ |
||
32 | 176 | public function __construct($value = 0, $unit = self::KG, array $options = []) |
|
36 | |||
37 | /* ------------------------------------------------------------------------------------------------ |
||
38 | | Getters & Setters |
||
39 | | ------------------------------------------------------------------------------------------------ |
||
40 | */ |
||
41 | /** |
||
42 | * Get the default names. |
||
43 | * |
||
44 | * @return array |
||
45 | */ |
||
46 | 176 | public function defaultNames() |
|
55 | |||
56 | /* ------------------------------------------------------------------------------------------------ |
||
57 | | Main Functions |
||
58 | | ------------------------------------------------------------------------------------------------ |
||
59 | */ |
||
60 | /** |
||
61 | * Make a weight instance. |
||
62 | * |
||
63 | * @param float|int $value |
||
64 | * @param string $unit |
||
65 | * @param array $options |
||
66 | * |
||
67 | * @return self |
||
68 | */ |
||
69 | 64 | public static function make($value = 0, $unit = self::KG, array $options = []) |
|
73 | |||
74 | /** |
||
75 | * Convert the weight to the given unit. |
||
76 | * |
||
77 | * @param string $to |
||
78 | * |
||
79 | * @return self |
||
80 | */ |
||
81 | 64 | public function to($to) |
|
89 | |||
90 | /** |
||
91 | * Convert the weight. |
||
92 | * |
||
93 | * @param string $from |
||
94 | * @param string $to |
||
95 | * @param float|int $value |
||
96 | * |
||
97 | * @return float|int |
||
98 | */ |
||
99 | 16 | public static function convert($from, $to, $value) |
|
103 | |||
104 | /* ------------------------------------------------------------------------------------------------ |
||
105 | | Calculation Functions |
||
106 | | ------------------------------------------------------------------------------------------------ |
||
107 | */ |
||
108 | /** |
||
109 | * Add the weight. |
||
110 | * |
||
111 | * @param float|int $value |
||
112 | * @param string $unit |
||
113 | * |
||
114 | * @return self |
||
115 | */ |
||
116 | 16 | public function addWeight($value, $unit = self::KG) |
|
120 | |||
121 | /** |
||
122 | * Sub the weight. |
||
123 | * |
||
124 | * @param float|int $value |
||
125 | * @param string $unit |
||
126 | * |
||
127 | * @return self |
||
128 | */ |
||
129 | 16 | public function subWeight($value, $unit = self::KG) |
|
133 | |||
134 | /* ------------------------------------------------------------------------------------------------ |
||
135 | | Other Functions |
||
136 | | ------------------------------------------------------------------------------------------------ |
||
137 | */ |
||
138 | /** |
||
139 | * Get the weight convert ratio. |
||
140 | * |
||
141 | * @param string $to |
||
142 | * @param string $from |
||
143 | * |
||
144 | * @return double|float|integer |
||
145 | */ |
||
146 | 16 | protected static function getRatio($to, $from) |
|
157 | |||
158 | /** |
||
159 | * Get all the weight ratios. |
||
160 | * |
||
161 | * @return array |
||
162 | */ |
||
163 | 16 | protected static function getRatios() |
|
177 | } |
||
178 |