You are here

public function Measurement::__construct in Physical Fields 8

Constructs a new Measurement object.

Parameters

string $number: The number.

string $unit: The unit.

File

src/Measurement.php, line 41

Class

Measurement
Provides a base class for measurement value objects.

Namespace

Drupal\physical

Code

public function __construct($number, $unit) {
  Calculator::assertNumberFormat($number);

  /** @var \Drupal\physical\UnitInterface $unit_class */
  $unit_class = MeasurementType::getUnitClass($this->type);
  $unit_class::assertExists($unit);
  $this->number = (string) $number;
  $this->unit = $unit;
}