Sha256: 7498879c450e8d97b4aabf0f7f25c73eb81bc536ea20ecc1051bc48dec260cff

Contents?: true

Size: 786 Bytes

Versions: 7

Compression:

Stored size: 786 Bytes

Contents

module Torque
  module Range
    def intersection(other)
      ActiveSupport::Deprecation.warn('Range extensions will be removed in future versions')
      raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range)

      new_min = self.cover?(other.min) ? other.min : other.cover?(min) ? min : nil
      new_max = self.cover?(other.max) ? other.max : other.cover?(max) ? max : nil

      new_min && new_max ? new_min..new_max : nil
    end
    alias_method :&, :intersection

    def union(other)
      ActiveSupport::Deprecation.warn('Range extensions will be removed in future versions')
      raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range)

      ([min, other.min].min)..([max, other.max].max)
    end
    alias_method :|, :union
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
torque-postgresql-2.4.5 lib/torque/range.rb
torque-postgresql-2.4.4 lib/torque/range.rb
torque-postgresql-2.4.3 lib/torque/range.rb
torque-postgresql-2.4.2 lib/torque/range.rb
torque-postgresql-2.4.1 lib/torque/range.rb
torque-postgresql-2.4.0 lib/torque/range.rb
torque-postgresql-2.3.0 lib/torque/range.rb