Sha256: e10100fa1e15f4a691449683c94e67f3198c91bf9285a7c0f701cf02ebf79310

Contents?: true

Size: 565 Bytes

Versions: 10

Compression:

Stored size: 565 Bytes

Contents

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

module UnitMeasurements
  module Comparison
    include Comparable

    # Implements +Comparable+ methods on the quantities of two measurements of
    # 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

10 entries across 10 versions & 1 rubygems

Version Path
unit_measurements-4.9.0 lib/unit_measurements/comparison.rb
unit_measurements-4.8.0 lib/unit_measurements/comparison.rb
unit_measurements-4.7.0 lib/unit_measurements/comparison.rb
unit_measurements-4.6.0 lib/unit_measurements/comparison.rb
unit_measurements-4.5.0 lib/unit_measurements/comparison.rb
unit_measurements-4.4.0 lib/unit_measurements/comparison.rb
unit_measurements-4.3.0 lib/unit_measurements/comparison.rb
unit_measurements-4.2.0 lib/unit_measurements/comparison.rb
unit_measurements-4.1.0 lib/unit_measurements/comparison.rb
unit_measurements-4.0.0 lib/unit_measurements/comparison.rb