ModraUp Ruby API Documentation Ruby API Reference

Class: Length

Inherits:
Numeric show all
Includes:
Comparable

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.

Examples:

pt = Geom::Point3d.new(25.4.mm, 0, 0)
pt.x.is_a?(Length)  #=> true
pt.x == 1.inch
12.to_l.to_f  #=> 12.0

Constants # collapse

Length::Decimal

Decimal = 0

Decimal length format.

Returns:

  • (Integer)
Length::Architectural

Architectural = 1

Architectural length format.

Returns:

  • (Integer)
Length::Engineering

Engineering = 2

Engineering length format.

Returns:

  • (Integer)
Length::Fractional

Fractional = 3

Fractional length format.

Returns:

  • (Integer)
Length::Inches

Inches = 0

Returns:

  • (Integer)
Length::Feet

Feet = 1

Feet.

Returns:

  • (Integer)
Length::Millimeter

Millimeter = 2

Returns:

  • (Integer)
Length::Centimeter

Centimeter = 3

Returns:

  • (Integer)
Length::Meter

Meter = 4

Unit in millimeters.

Returns:

  • (Integer)
Length::Yard

Yard = 5

Inch.

Returns:

  • (Integer)
Length::SquareInches

SquareInches = 0

square inches.

Returns:

  • (Integer)
Length::SquareFeet

SquareFeet = 1

Square feet.

Returns:

  • (Integer)
Length::SquareMillimeter

SquareMillimeter = 2

Square millimeter.

Returns:

  • (Integer)
Length::SquareCentimeter

SquareCentimeter = 3

SquareCentimeter.

Returns:

  • (Integer)
Length::SquareMeter

SquareMeter = 4

Square Meter.

Returns:

  • (Integer)
Length::SquareYard

SquareYard = 5

SquareYard.

Returns:

  • (Integer)
Length::CubicInches

CubicInches = 0

cubic inches.

Returns:

  • (Integer)
Length::CubicFeet

CubicFeet = 1

Cubic feet.

Returns:

  • (Integer)
Length::CubicMillimeter

CubicMillimeter = 2

Cubic millimeter unit.

Returns:

  • (Integer)
Length::CubicCentimeter

CubicCentimeter = 3

Cubic centimeter.

Returns:

  • (Integer)
Length::CubicMeter

CubicMeter = 4

Cubic Meter.

Returns:

  • (Integer)
Length::CubicYard

CubicYard = 5

Cubic yard.

Returns:

  • (Integer)
Length::Liter

Liter = 6

Cubic Centimeters.

Returns:

  • (Integer)
Length::USGallon

USGallon = 7

U.S. gallon.

Returns:

  • (Integer)

Class Method Summary # collapse

  • .new ⇒ Length
    Construct in inches. Plugins typically write 12.to_l or 25.4.mm.

Instance Method Summary # collapse

Inherited from Numeric

Class Method Details

Length.new ⇒ lengthLength.new(inches) ⇒ length

Construct in inches. Plugins typically write 12.to_l or 25.4.mm.

Parameters:

  • inches (Numeric, Length)

Returns:

  • (Length)

Examples:

Length.new(12).to_f  #=> 12.0

Instance Method Details

length.to_f ⇒ Float

Convert to inches as a Float.

Returns:

  • (Float)

Examples:

12.to_l.to_f  #=> 12.0

length.to_s ⇒ String

Format the length according to the current model's units and precision.

Returns:

  • (String)

Examples:

1.inch.to_s

length.inspect ⇒ String

An unformatted inch string, unrelated to the model's display units.

Returns:

  • (String)

Examples:

12.to_l.inspect  #=> "12.0"

length <=> other ⇒ Integer

Three-way comparison with length tolerance. Differences not exceeding 0.001 inches are considered equal.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Integer, nil)

Examples:

(20.to_l <=> 30.to_l)  #=> -1

length == other ⇒ Boolean

Equal with length tolerance. 1.inch == 1 is true (bare numbers are in inches).

Parameters:

  • other (Object)

Returns:

  • (Boolean)

Examples:

1.inch == 1.000001.inch  #=> true

length.hash ⇒ Integer

Returns:

  • (Integer) A hash of internal inch values, unaffected by the display units.

length < other ⇒ Boolean

Length tolerance: Less than and differing by more than 0.001 inches.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Boolean)

Examples:

1.inch < 2.inch  #=> true

length <= other ⇒ Boolean

Length tolerance: Less than, or within 0.001 inches.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Boolean)

Examples:

1.inch <= 1.0005.inch  #=> true

length > other ⇒ Boolean

Length tolerance: greater than and differing by more than 0.001 inches.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Boolean)

Examples:

2.inch > 1.inch  #=> true

length >= other ⇒ Boolean

Length tolerance: Greater than, or within 0.001 inches.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Boolean)

Examples:

1.inch >= 1.0005.inch  #=> true

length + other ⇒ number

Add, the naked number in inches, and the result is a regular numerical value.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Numeric)

Examples:

1.inch + 1.inch  #=> 2.0

length - other ⇒ number

Subtract, the bare number in inches results in a regular numerical value.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Numeric)

Examples:

2.inch - 1  #=> 1.0

length * other ⇒ number

Multiply by Ruby Length in inches, resulting in a plain numerical value.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Numeric)

Examples:

1.inch * 2  #=> 2.0

length / other ⇒ number

Divide by inches; like Float, division by zero produces Infinity or NaN.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Numeric)

Examples:

1.inch / 2  #=> 0.5

length ** other ⇒ number

Raise to a power in inches, following the semantics of Float; negative non-integer powers can return Complex.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Float, Complex)

Examples:

3.inch ** 2  #=> 9.0

length % other ⇒ number

Returns the remainder with the same sign as the divisor, following Float modulo rules.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Numeric)

Examples:

(-5).inch % 3  #=> 1.0

length.modulo(other) ⇒ number

Works the same as %, taking the modulus according to Float rules.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Numeric)

Examples:

5.inch.modulo(3)  #=> 2.0

length.remainder(other) ⇒ number

Returns the remainder according to Float rules, with the result having the same sign as the dividend.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Numeric)

Examples:

(-5).inch.remainder(3)  #=> -2.0

length.div(other) ⇒ number

Divides by a Float according to floating-point division rules and returns the floor of the quotient.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Integer)

Examples:

5.inch.div(2)  #=> 2

length.divmod(other) ⇒ number

Returns the integer division quotient and remainder according to Float rules.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Array(Integer, Float))

Examples:

5.inch.divmod(2)  #=> [2, 1.0]

length.fdiv(other) ⇒ number

Divides by the Float according to Float rules.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Numeric)

Examples:

5.inch.fdiv(2)  #=> 2.5

length.quo(other) ⇒ number

Divides by the Float according to Float rules.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Numeric)

Examples:

5.inch.quo(2)  #=> 2.5

-length ⇒ Float

Negate, return inches as a Float.

Returns:

  • (Float)

+length ⇒ Float

Returns the length in inches as a Float.

Returns:

  • (Float)

length.abs ⇒ Float

Returns the absolute value as a Float in inches.

Returns:

  • (Float)

length.magnitude ⇒ Float

Returns an Inch Float magnitude, similar to abs.

Returns:

  • (Float)

length.to_i ⇒ Integer

Truncate to the nearest integer in inches.

Returns:

  • (Integer)

length.to_int ⇒ Integer

Returns the integer value of the length, equivalent to using to_i.

Returns:

  • (Integer)

length.to_r ⇒ Rational

Returns a precise rational number representation of the length in inches.

Returns:

  • (Rational)

length.finite? ⇒ Boolean

Query if the inch numerical value is finite.

Returns:

  • (Boolean)

length.infinite? ⇒ Integer or nil

Returns 1 for positive infinity, -1 for negative infinity, and nil otherwise.

Returns:

  • (Integer, nil)

length.nan? ⇒ Boolean

Query if the inch numerical value is NaN.

Returns:

  • (Boolean)

length.round(ndigits = 0) ⇒ number

Round to the nearest integer according to Float rounding rules, supporting the half: keyword.

Parameters:

  • ndigits (Integer)

Returns:

  • (Integer, Float)

length.floor(ndigits = 0) ⇒ number

Round down to the nearest integer as per Float rules.

Parameters:

  • ndigits (Integer)

Returns:

  • (Integer, Float)

length.ceil(ndigits = 0) ⇒ number

Ceils to the nearest integer as per Float rules.

Parameters:

  • ndigits (Integer)

Returns:

  • (Integer, Float)

length.truncate(ndigits = 0) ⇒ number

Truncates to zero following Float rules.

Parameters:

  • ndigits (Integer)

Returns:

  • (Integer, Float)

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.

Parameters:

  • other (Numeric, Length)

Returns:

  • (Array(Float, Float))

Examples:

1.inch.coerce(2)  #=> [2.0, 1.0]