Class: Length
Overview
A length stored in inches. In the API since 2015, Length is separate from Float. ModraUp derives Length from Numeric. Equality, ordering, and <=> use a tolerance of 0.001 inches. Arithmetic operates on inches and returns an ordinary number, usually a Float. Call to_l to convert the result back to a Length. inspect displays inches. to_s uses the current model's display units.
Constants # collapse
- Length::Decimal
Decimal = 0
Decimal length format.
- Length::Architectural
Architectural = 1
Architectural length format.
- Length::Engineering
Engineering = 2
Engineering length format.
- Length::Fractional
Fractional = 3
Fractional length format.
- Length::Inches
Inches = 0
- Length::Feet
Feet = 1
Feet.
- Length::Millimeter
Millimeter = 2
- Length::Centimeter
Centimeter = 3
- Length::Meter
Meter = 4
Unit in millimeters.
- Length::Yard
Yard = 5
Inch.
- Length::SquareInches
SquareInches = 0
square inches.
- Length::SquareFeet
SquareFeet = 1
Square feet.
- Length::SquareMillimeter
SquareMillimeter = 2
Square millimeter.
- Length::SquareCentimeter
SquareCentimeter = 3
SquareCentimeter.
- Length::SquareMeter
SquareMeter = 4
Square Meter.
- Length::SquareYard
SquareYard = 5
SquareYard.
- Length::CubicInches
CubicInches = 0
cubic inches.
- Length::CubicFeet
CubicFeet = 1
Cubic feet.
- Length::CubicMillimeter
CubicMillimeter = 2
Cubic millimeter unit.
- Length::CubicCentimeter
CubicCentimeter = 3
Cubic centimeter.
- Length::CubicMeter
CubicMeter = 4
Cubic Meter.
- Length::CubicYard
CubicYard = 5
Cubic yard.
- Length::Liter
Liter = 6
Cubic Centimeters.
- Length::USGallon
USGallon = 7
U.S. gallon.
Class Method Summary # collapse
-
.new ⇒ Length
Construct in inches. Plugins typically write 12.to_l or 25.4.mm.
Instance Method Summary # collapse
-
#to_f ⇒ Float
Convert to inches as a Float.
-
#to_s ⇒ String
Format the length according to the current model's units and precision.
-
#inspect ⇒ String
An unformatted inch string, unrelated to the model's display units.
-
#<=> ⇒ Integer, nil
Three-way comparison with length tolerance. Differences not exceeding 0.001 inches are considered equal.
-
#== ⇒ Boolean
Equal with length tolerance. 1.inch == 1 is true (bare numbers are in inches).
- #hash ⇒ Integer
-
#< ⇒ Boolean
Length tolerance: Less than and differing by more than 0.001 inches.
-
#<= ⇒ Boolean
Length tolerance: Less than, or within 0.001 inches.
-
#> ⇒ Boolean
Length tolerance: greater than and differing by more than 0.001 inches.
-
#>= ⇒ Boolean
Length tolerance: Greater than, or within 0.001 inches.
-
#+ ⇒ Numeric
Add, the naked number in inches, and the result is a regular numerical value.
-
#- ⇒ Numeric
Subtract, the bare number in inches results in a regular numerical value.
-
#* ⇒ Numeric
Multiply by Ruby Length in inches, resulting in a plain numerical value.
-
#/ ⇒ Numeric
Divide by inches; like Float, division by zero produces Infinity or NaN.
-
#** ⇒ Float, Complex
Raise to a power in inches, following the semantics of Float; negative non-integer powers can return Complex.
-
#% ⇒ Numeric
Returns the remainder with the same sign as the divisor, following Float modulo rules.
-
#modulo(other) ⇒ Numeric
Works the same as %, taking the modulus according to Float rules.
-
#remainder(other) ⇒ Numeric
Returns the remainder according to Float rules, with the result having the same sign as the dividend.
-
#div(other) ⇒ Integer
Divides by a Float according to floating-point division rules and returns the floor of the quotient.
-
#divmod(other) ⇒ Array(Integer, Float)
Returns the integer division quotient and remainder according to Float rules.
-
#fdiv(other) ⇒ Numeric
Divides by the Float according to Float rules.
-
#quo(other) ⇒ Numeric
Divides by the Float according to Float rules.
-
#-@ ⇒ Float
Negate, return inches as a Float.
-
#+@ ⇒ Float
Returns the length in inches as a Float.
-
#abs ⇒ Float
Returns the absolute value as a Float in inches.
-
#magnitude ⇒ Float
Returns an Inch Float magnitude, similar to abs.
-
#to_i ⇒ Integer
Truncate to the nearest integer in inches.
-
#to_int ⇒ Integer
Returns the integer value of the length, equivalent to using to_i.
-
#to_r ⇒ Rational
Returns a precise rational number representation of the length in inches.
-
#finite? ⇒ Boolean
Query if the inch numerical value is finite.
-
#infinite? ⇒ Integer, nil
Returns 1 for positive infinity, -1 for negative infinity, and nil otherwise.
-
#nan? ⇒ Boolean
Query if the inch numerical value is NaN.
-
#round(ndigits = 0) ⇒ Integer, Float
Round to the nearest integer according to Float rounding rules, supporting the half: keyword.
-
#floor(ndigits = 0) ⇒ Integer, Float
Round down to the nearest integer as per Float rules.
-
#ceil(ndigits = 0) ⇒ Integer, Float
Ceils to the nearest integer as per Float rules.
-
#truncate(ndigits = 0) ⇒ Integer, Float
Truncates to zero following Float rules.
-
#coerce(other) ⇒ Array(Float, Float)
Coerce the operand to a Float according to Float rules, ensuring that the numeric value on the left side of the operation returns a regular number.
Inherited from Numeric
-
#mm ⇒ Length
Treat the number as millimeters to get the internal inches Length. 25.4.mm is 1 inch.
-
#cm ⇒ Length
Treat the number as centimeters.
-
#m ⇒ Length
Treat the numbers as meters.
-
#km ⇒ Length
Treat the number as kilometers.
-
#inch ⇒ Length
Treat the number as inches. Same as #to_l.
-
#feet ⇒ Length
Treat the number as feet (1 foot = 12 inches).
-
#yard ⇒ Length
Treat numbers as codes (1 code = 36 inches).
-
#mile ⇒ Length
Treat the numbers as miles.
-
#to_mm ⇒ Float
Convert itself from inches to millimeters.
-
#to_cm ⇒ Float
Convert itself from inches to centimeters.
-
#to_m ⇒ Float
Convert itself from inches to meters.
-
#to_km ⇒ Float
Convert itself from inches to kilometers.
-
#to_inch ⇒ Float
Convert itself to inches, yielding the value in inches (numeric value remains unchanged).
-
#to_feet ⇒ Float
Convert itself to feet from inches.
-
#to_yard ⇒ Float
Convert itself to yards by dividing by 36 inches.
-
#to_mile ⇒ Float
Convert itself to miles from inches.
-
#to_mm2 ⇒ Float
Convert itself from square inches to square millimeters.
-
#to_cm2 ⇒ Float
Convert itself to square inches and then convert to square centimeters.
-
#to_m2 ⇒ Float
Convert itself to square meters from square inches.
-
#to_km2 ⇒ Float
Convert itself from square inches to square kilometers.
-
#to_inch2 ⇒ Float
Convert itself to square inches, yielding the value in square inches (numeric value remains unchanged).
-
#to_feet2 ⇒ Float
Convert itself to square feet from square inches.
-
#to_yard2 ⇒ Float
Convert itself from square inches to square yards.
-
#to_mile2 ⇒ Float
Convert itself to square miles from square inches.
-
#to_l ⇒ Length
Treat the number as inches to get Length.
-
#degrees ⇒ Float
Convert degrees to radians. +90.degrees is approximately π/2.
-
#radians ⇒ Float
Convert radians to degrees.
Class Method Details
Length.new ⇒ lengthLength.new(inches) ⇒ length
Construct in inches. Plugins typically write 12.to_l or 25.4.mm.
Instance Method Details
length.to_f ⇒ Float
Convert to inches as a Float.
length.to_s ⇒ String
Format the length according to the current model's units and precision.
length.inspect ⇒ String
An unformatted inch string, unrelated to the model's display units.
length <=> other ⇒ Integer
Three-way comparison with length tolerance. Differences not exceeding 0.001 inches are considered equal.
length == other ⇒ Boolean
Equal with length tolerance. 1.inch == 1 is true (bare numbers are in inches).
length.hash ⇒ Integer
length < other ⇒ Boolean
Length tolerance: Less than and differing by more than 0.001 inches.
length <= other ⇒ Boolean
Length tolerance: Less than, or within 0.001 inches.
length > other ⇒ Boolean
Length tolerance: greater than and differing by more than 0.001 inches.
length >= other ⇒ Boolean
Length tolerance: Greater than, or within 0.001 inches.
length + other ⇒ number
Add, the naked number in inches, and the result is a regular numerical value.
length - other ⇒ number
Subtract, the bare number in inches results in a regular numerical value.
length * other ⇒ number
Multiply by Ruby Length in inches, resulting in a plain numerical value.
length / other ⇒ number
Divide by inches; like Float, division by zero produces Infinity or NaN.
length ** other ⇒ number
Raise to a power in inches, following the semantics of Float; negative non-integer powers can return Complex.
length % other ⇒ number
Returns the remainder with the same sign as the divisor, following Float modulo rules.
length.modulo(other) ⇒ number
Works the same as %, taking the modulus according to Float rules.
length.remainder(other) ⇒ number
Returns the remainder according to Float rules, with the result having the same sign as the dividend.
length.div(other) ⇒ number
Divides by a Float according to floating-point division rules and returns the floor of the quotient.
length.divmod(other) ⇒ number
Returns the integer division quotient and remainder according to Float rules.
length.fdiv(other) ⇒ number
Divides by the Float according to Float rules.
length.quo(other) ⇒ number
Divides by the Float according to Float rules.
-length ⇒ Float
Negate, return inches as a Float.
+length ⇒ Float
Returns the length in inches as a Float.
length.abs ⇒ Float
Returns the absolute value as a Float in inches.
length.magnitude ⇒ Float
Returns an Inch Float magnitude, similar to abs.
length.to_i ⇒ Integer
Truncate to the nearest integer in inches.
length.to_int ⇒ Integer
Returns the integer value of the length, equivalent to using to_i.
length.to_r ⇒ Rational
Returns a precise rational number representation of the length in inches.
length.finite? ⇒ Boolean
Query if the inch numerical value is finite.
length.infinite? ⇒ Integer or nil
Returns 1 for positive infinity, -1 for negative infinity, and nil otherwise.
length.nan? ⇒ Boolean
Query if the inch numerical value is NaN.
length.round(ndigits = 0) ⇒ number
Round to the nearest integer according to Float rounding rules, supporting the half: keyword.
length.floor(ndigits = 0) ⇒ number
Round down to the nearest integer as per Float rules.
length.ceil(ndigits = 0) ⇒ number
Ceils to the nearest integer as per Float rules.
length.truncate(ndigits = 0) ⇒ number
Truncates to zero following Float rules.
length.coerce(other) ⇒ Array
Coerce the operand to a Float according to Float rules, ensuring that the numeric value on the left side of the operation returns a regular number.