You are here

public function SassNumber::__construct in Sassy 7.3

Same name and namespace in other branches
  1. 7 phamlp/sass/script/literals/SassNumber.php \SassNumber::__construct()

class constructor. Sets the value and units of the number.

Parameters

string number:

Return value

SassNumber

Overrides SassLiteral::__construct

File

phpsass/script/literals/SassNumber.php, line 77

Class

SassNumber
SassNumber class. Provides operations and type testing for Sass numbers. Units are of the passed value are converted the those of the class value if it has units. e.g. 2cm + 20mm = 4cm while 2 + 20mm = 22mm. @package PHamlP @subpackage …

Code

public function __construct($value) {
  preg_match(self::MATCH, $value, $matches);
  $this->value = $matches[self::VALUE];
  if (!empty($matches[self::UNITS])) {
    $units = explode('/', $matches[self::UNITS]);
    $numeratorUnits = $denominatorUnits = array();
    foreach (explode('*', $units[0]) as $unit) {
      $numeratorUnits[] = trim($unit);
    }
    if (isset($units[1])) {
      foreach (explode('*', $units[1]) as $unit) {
        $denominatorUnits[] = trim($unit);
      }
    }
    $units = $this
      ->removeCommonUnits($numeratorUnits, $denominatorUnits);
    $this->numeratorUnits = $units[0];
    $this->denominatorUnits = $units[1];
  }
}