PHP Class SassNumber

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.
Inheritance: extends SassLiteral
ファイルを表示 Open project: richthegeek/phpsass Class Usage Examples

Public Properties

Property Type Description
$inExpression whether this number is in an expression or a literal number Used to determine whether division should take place

Public Methods

Method Description
__construct ( $value ) : SassNumber class constructor.
coerce ( array $numeratorUnits, array $denominatorUnits ) : SassNumber Returns the value of this number converted to other units.
getDenominatorUnits ( ) : string Returns the denominator units of this number.
getNumeratorUnits ( ) : string Returns the numerator units of this number.
getUnits ( ) : string Returns the units of this number.
getValue ( ) : float Returns the value of this number.
hasLegalUnits ( ) : boolean Returns a value indicating if this number has units that can be represented in CSS.
hasUnits ( ) : boolean Returns a value indicating if this number has units.
isComparableTo ( $other ) : boolean Returns a value indicating if this number can be compared to other.
isInt ( ) : boolean Returns a value indicating if this number is an integer.
isUnitless ( ) : boolean Returns a value indicating if this number is unitless.
isa ( string $subject ) : mixed Returns a value indicating if a token of this type can be matched at the start of the subject string.
length ( ) : integer Returns the number of values of SassNumber
nth ( $i ) : SassBoolean | SassNumber Returns the nth value of the SassNumber
op_div ( $other ) : mixed Divides this value by the value of other
op_eq ( $other ) : SassBoolean The SassScript == operation.
op_gt ( sassLiteral $other ) : SassBoolean The SassScript > operation.
op_gte ( sassLiteral $other ) : SassBoolean The SassScript >= operation.
op_lt ( sassLiteral $other ) : SassBoolean The SassScript < operation.
op_lte ( sassLiteral $other ) : SassBoolean The SassScript <= operation.
op_minus ( $other ) : mixed Subtracts the value of other from this value
op_modulo ( string $other ) : mixed Takes the modulus (remainder) of this value divided by the value of other
op_plus ( $other ) : mixed Adds the value of other to the value of this
op_times ( $other ) : mixed Multiplies this value by the value of other
op_unary_concat ( )
op_unary_minus ( ) : SassNumber Unary - operator
op_unary_plus ( ) : SassNumber Unary + operator
toInt ( ) : integer Returns the integer value.
toString ( ) : string Converts the number to a string with it's units if any.
unitString ( $numeratorUnits, $denominatorUnits ) : string Returns a string representation of the units.

Private Methods

Method Description
areConvertable ( array $units ) : boolean Returns a value indicating if all the units are capable of being converted
coercionFactor ( array $fromUnits, array $toUnits ) : float Calculates the corecion factor to apply to the value
convert ( SassNumber $other ) : SassNumber Converts values and units.
removeCommonUnits ( array $u1, array $u2 ) : array Removes common units from each set.

Method Details

__construct() public method

Sets the value and units of the number.
public __construct ( $value ) : SassNumber
return SassNumber

coerce() public method

The conversion takes into account the relationship between e.g. mm and cm, as well as between e.g. in and cm. If this number is unitless, it will simply return itself with the given units.
public coerce ( array $numeratorUnits, array $denominatorUnits ) : SassNumber
$numeratorUnits array
$denominatorUnits array
return SassNumber

getDenominatorUnits() public method

Returns the denominator units of this number.
public getDenominatorUnits ( ) : string
return string the denominator units of this number

getNumeratorUnits() public method

Returns the numerator units of this number.
public getNumeratorUnits ( ) : string
return string the numerator units of this number

getUnits() public method

Returns the units of this number.
public getUnits ( ) : string
return string the units of this number

getValue() public method

Returns the value of this number.
public getValue ( ) : float
return float the value of this number.

hasLegalUnits() public method

Returns a value indicating if this number has units that can be represented in CSS.
public hasLegalUnits ( ) : boolean
return boolean true if this number has units that can be represented in CSS, false if not

hasUnits() public method

Returns a value indicating if this number has units.
public hasUnits ( ) : boolean
return boolean true if this number has, false if not

isComparableTo() public method

Returns a value indicating if this number can be compared to other.
public isComparableTo ( $other ) : boolean
return boolean true if this number can be compared to other, false if not

isInt() public method

Returns a value indicating if this number is an integer.
public isInt ( ) : boolean
return boolean true if this number is an integer, false if not

isUnitless() public method

Returns a value indicating if this number is unitless.
public isUnitless ( ) : boolean
return boolean true if this number is unitless, false if not

isa() public static method

Returns a value indicating if a token of this type can be matched at the start of the subject string.
public static isa ( string $subject ) : mixed
$subject string the subject string
return mixed match at the start of the string or false if no match

length() public method

Returns the number of values of SassNumber
public length ( ) : integer
return integer

nth() public method

Returns the nth value of the SassNumber
public nth ( $i ) : SassBoolean | SassNumber
return SassBoolean | SassNumber

op_div() public method

Divides this value by the value of other
public op_div ( $other ) : mixed
return mixed SassNumber if other is a SassNumber or SassColour if it is a SassColour

op_eq() public method

The SassScript == operation.
public op_eq ( $other ) : SassBoolean
return SassBoolean SassBoolean object with the value true if the values of this and other are equal, false if they are not

op_gt() public method

The SassScript > operation.
public op_gt ( sassLiteral $other ) : SassBoolean
$other sassLiteral the value to compare to this
return SassBoolean SassBoolean object with the value true if the values of this is greater than the value of other, false if it is not

op_gte() public method

The SassScript >= operation.
public op_gte ( sassLiteral $other ) : SassBoolean
$other sassLiteral the value to compare to this
return SassBoolean SassBoolean object with the value true if the values of this is greater than or equal to the value of other, false if it is not

op_lt() public method

The SassScript < operation.
public op_lt ( sassLiteral $other ) : SassBoolean
$other sassLiteral the value to compare to this
return SassBoolean SassBoolean object with the value true if the values of this is less than the value of other, false if it is not

op_lte() public method

The SassScript <= operation.
public op_lte ( sassLiteral $other ) : SassBoolean
$other sassLiteral the value to compare to this
return SassBoolean SassBoolean object with the value true if the values of this is less than or equal to the value of other, false if it is not

op_minus() public method

Subtracts the value of other from this value
public op_minus ( $other ) : mixed
return mixed SassNumber if other is a SassNumber or SassColour if it is a SassColour

op_modulo() public method

Takes the modulus (remainder) of this value divided by the value of other
public op_modulo ( string $other ) : mixed
$other string value to divide by
return mixed SassNumber if other is a SassNumber or SassColour if it is a SassColour

op_plus() public method

Adds the value of other to the value of this
public op_plus ( $other ) : mixed
return mixed SassNumber if other is a SassNumber or SassColour if it is a SassColour

op_times() public method

Multiplies this value by the value of other
public op_times ( $other ) : mixed
return mixed SassNumber if other is a SassNumber or SassColour if it is a SassColour

op_unary_concat() public method

public op_unary_concat ( )

op_unary_minus() public method

Unary - operator
public op_unary_minus ( ) : SassNumber
return SassNumber the negative value of this number

op_unary_plus() public method

Unary + operator
public op_unary_plus ( ) : SassNumber
return SassNumber the value of this number

toInt() public method

Returns the integer value.
public toInt ( ) : integer
return integer the integer value.

toString() public method

If the units are px the result is rounded down to the nearest integer, otherwise the result is rounded to the specified precision.
public toString ( ) : string
return string number as a string with it's units if any

unitString() public method

Returns a string representation of the units.
public unitString ( $numeratorUnits, $denominatorUnits ) : string
return string the units

Property Details

$inExpression public_oe property

whether this number is in an expression or a literal number Used to determine whether division should take place
public $inExpression