Class | Sass::Script::Number |
In: |
lib/sass/script/number.rb
|
Parent: | Literal |
A SassScript object representing a number. SassScript numbers can have decimal values, and can also have units. For example, `12`, `1px`, and `10.45em` are all valid values.
Numbers can also have more complex units, such as `1px*em/in`. These cannot be inputted directly in Sass code at the moment.
PRECISION | = | 1000.0 | The precision with which numbers will be printed to CSS files. For example, if this is `1000.0`, `3.1415926` will be printed as `3.142`. @api public | |
CONVERTABLE_UNITS | = | {"in" => 0, "cm" => 1, "pc" => 2, "mm" => 3, "pt" => 4} | A hash of unit names to their index in the conversion table | |
CONVERSION_TABLE | = | [[ 1, 2.54, 6, 25.4, 72 ], # in [ nil, 1, 2.36220473, 10, 28.3464567], # cm [ nil, nil, 1, 4.23333333, 12 ], # pc [ nil, nil, nil, 1, 2.83464567], # mm [ nil, nil, nil, nil, 1 ]] |
denominator_units | [R] | A list of units in the denominator of the number. For example, `1px*em/in*cm` would return `["in", "cm"]` @return [Array<String>] |
numerator_units | [R] | A list of units in the numerator of the number. For example, `1px*em/in*cm` would return `["px", "em"]` @return [Array<String>] |
original | [RW] |
The original representation of this number. For example, although the
result of `1px/2px` is `0.5`, the value of `original` is
`"1px/2px"`.
This is only non-nil when the original value should be used as the CSS value, as in `font: 1px/2px`. @return [Boolean, nil] |
value | [R] |
The Ruby value of the number.
@return [Numeric] |
Returns this number converted to other units. 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 has no units, it will simply return itself with the given units.
An incompatible coercion, e.g. between px and cm, will raise an error.
@param num_units [Array<String>] The numerator units to coerce this number into.
See {\#numerator\_units}
@param den_units [Array<String>] The denominator units to coerce this number into.
See {\#denominator\_units}
@return [Number] The number with the new units @raise [Sass::UnitConversionError] if the given units are incompatible with the number‘s
current units
@param other [Number] A number to decide if it can be compared with this number. @return [Boolean] Whether or not this number can be compared with the other.
The SassScript `/` operation. Its functionality depends on the type of its argument:
{Number} : Divides this number by the other, converting units appropriately.
{Literal} : See {Literal#div}.
@param other [Literal] The right-hand side of the operator @return [Literal] The result of the operation
The SassScript `==` operation.
@param other [Literal] The right-hand side of the operator @return [Boolean] Whether this number is equal to the other object
The SassScript `>` operation.
@param other [Number] The right-hand side of the operator @return [Boolean] Whether this number is greater than the other @raise [NoMethodError] if `other` is an invalid type
The SassScript `>=` operation.
@param other [Number] The right-hand side of the operator @return [Boolean] Whether this number is greater than or equal to the other @raise [NoMethodError] if `other` is an invalid type
@return [Boolean] Whether or not this number has units that can be represented in CSS
(that is, zero or one \{#numerator\_units}).
The SassScript `<` operation.
@param other [Number] The right-hand side of the operator @return [Boolean] Whether this number is less than the other @raise [NoMethodError] if `other` is an invalid type
The SassScript `<=` operation.
@param other [Number] The right-hand side of the operator @return [Boolean] Whether this number is less than or equal to the other @raise [NoMethodError] if `other` is an invalid type
The SassScript binary `-` operation (e.g. `$a - $b`). Its functionality depends on the type of its argument:
{Number} : Subtracts this number from the other, converting units if possible.
{Literal} : See {Literal#minus}.
@param other [Literal] The right-hand side of the operator @return [Literal] The result of the operation @raise [Sass::UnitConversionError] if `other` is a number with incompatible units
The SassScript `%` operation.
@param other [Number] The right-hand side of the operator @return [Number] This number modulo the other @raise [NoMethodError] if `other` is an invalid type @raise [Sass::UnitConversionError] if `other` has any units
The SassScript `+` operation. Its functionality depends on the type of its argument:
{Number} : Adds the two numbers together, converting units if possible.
{Color} : Adds this number to each of the RGB color channels.
{Literal} : See {Literal#plus}.
@param other [Literal] The right-hand side of the operator @return [Literal] The result of the operation @raise [Sass::UnitConversionError] if `other` is a number with incompatible units
The SassScript `*` operation. Its functionality depends on the type of its argument:
{Number} : Multiplies the two numbers together, converting units appropriately.
{Color} : Multiplies each of the RGB color channels by this number.
@param other [Number, Color] The right-hand side of the operator @return [Number, Color] The result of the operation @raise [NoMethodError] if `other` is an invalid type
@return [Fixnum] The integer value of the number @raise [Sass::SyntaxError] if the number isn‘t an integer
@return [String] The CSS representation of this number @raise [Sass::SyntaxError] if this number has units that can‘t be used in CSS
(e.g. `px*in`)
The SassScript unary `-` operation (e.g. `-$a`).
@return [Number] The negative value of this number
The SassScript unary `+` operation (e.g. `+$a`).
@return [Number] The value of this number
Returns a human readable representation of the units in this number. For complex units this takes the form of: numerator_unit1 * numerator_unit2 / denominator_unit1 * denominator_unit2 @return [String] a string that represents the units in this number