1 | <?php |
||
7 | class Weight implements WeightInterface |
||
8 | { |
||
9 | /** |
||
10 | * Grams per kilogram. |
||
11 | */ |
||
12 | const GRAMS_PER_KILOGRAM = 1000; |
||
13 | |||
14 | /** |
||
15 | * Grams per pound. |
||
16 | */ |
||
17 | const GRAMS_PER_POUND = 453.592; |
||
18 | |||
19 | /** |
||
20 | * Weight in grams. |
||
21 | * |
||
22 | * @var float |
||
23 | */ |
||
24 | protected $grams; |
||
25 | |||
26 | /** |
||
27 | * Create a new instance of Weight. |
||
28 | * |
||
29 | * @param float $grams |
||
30 | */ |
||
31 | 10 | protected function __construct($grams) |
|
35 | |||
36 | /** |
||
37 | * Create weight from grams. |
||
38 | * |
||
39 | * @param float $grams |
||
40 | * |
||
41 | * @return \Jne\Contracts\Foudation\WeightInterface |
||
42 | */ |
||
43 | 3 | public static function fromGrams($grams) |
|
47 | |||
48 | /** |
||
49 | * Create weight from kilograms. |
||
50 | * |
||
51 | * @param float $kilograms |
||
52 | * |
||
53 | * @return \Jne\Contracts\Foudation\WeightInterface |
||
54 | */ |
||
55 | 5 | public static function fromKilograms($kilograms) |
|
59 | |||
60 | /** |
||
61 | * Create weight from pounds. |
||
62 | * |
||
63 | * @param float $pounds |
||
64 | * |
||
65 | * @return \Jne\Contracts\Foudation\WeightInterface |
||
66 | */ |
||
67 | 2 | public static function fromPounds($pounds) |
|
71 | |||
72 | /** |
||
73 | * Get weight in grams. |
||
74 | * |
||
75 | * @return float |
||
76 | */ |
||
77 | 7 | public function grams() |
|
81 | |||
82 | /** |
||
83 | * Get weight in kilograms. |
||
84 | * |
||
85 | * @return float |
||
86 | */ |
||
87 | 2 | public function kilograms() |
|
91 | |||
92 | /** |
||
93 | * Get weight in pounds. |
||
94 | * |
||
95 | * @return float |
||
96 | */ |
||
97 | 1 | public function pounds() |
|
101 | } |
||
102 |