Sha256: 34ee11236e8823f65323593b3cc57a5daaaca7cefb97f6fd3a8a26463ab152eb

Contents?: true

Size: 537 Bytes

Versions: 24

Compression:

Stored size: 537 Bytes

Contents

# -*- encoding: utf-8 -*-
# -*- frozen_string_literal: true -*-
# -*- warn_indent: true -*-

module UnitMeasurements
  module Comparison
    include Comparable

    # Compares the quantities of two measurements within the same unit group.
    #
    # @example
    #   UnitMeasurements::Weight.new(1, "kg") == UnitMeasurements::Weight.new(1, :kg)
    #   => true
    #
    # @return [Boolean]
    def <=>(object)
      return nil unless object.is_a?(self.class)

      quantity <=> object.convert_to(unit.name).quantity
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
unit_measurements-3.8.0 lib/unit_measurements/comparison.rb
unit_measurements-3.7.0 lib/unit_measurements/comparison.rb
unit_measurements-3.6.0 lib/unit_measurements/comparison.rb
unit_measurements-3.5.0 lib/unit_measurements/comparison.rb
unit_measurements-3.4.1 lib/unit_measurements/comparison.rb
unit_measurements-3.3.0 lib/unit_measurements/comparison.rb
unit_measurements-3.4.0 lib/unit_measurements/comparison.rb
unit_measurements-3.2.0 lib/unit_measurements/comparison.rb
unit_measurements-3.1.0 lib/unit_measurements/comparison.rb
unit_measurements-3.0.0 lib/unit_measurements/comparison.rb
unit_measurements-2.6.2 lib/unit_measurements/comparison.rb
unit_measurements-2.6.1 lib/unit_measurements/comparison.rb
unit_measurements-2.6.0 lib/unit_measurements/comparison.rb
unit_measurements-2.5.0 lib/unit_measurements/comparison.rb
unit_measurements-2.4.0 lib/unit_measurements/comparison.rb
unit_measurements-2.3.0 lib/unit_measurements/comparison.rb
unit_measurements-2.2.0 lib/unit_measurements/comparison.rb
unit_measurements-2.1.0 lib/unit_measurements/comparison.rb
unit_measurements-1.7.0 lib/unit_measurements/comparison.rb
unit_measurements-1.6.0 lib/unit_measurements/comparison.rb