Sha256: 34910fad14848f0de42c0a2f4523394ac5f2802228a0feb74605536a3ef96e8c

Contents?: true

Size: 626 Bytes

Versions: 20

Compression:

Stored size: 626 Bytes

Contents

module Torque
  module Range
    def intersection(other)
      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)
      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

  ::Range.include(Range)
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
torque-postgresql-2.1.3 lib/torque/range.rb
torque-postgresql-1.1.8 lib/torque/range.rb
torque-postgresql-2.1.2 lib/torque/range.rb
torque-postgresql-2.1.1 lib/torque/range.rb
torque-postgresql-2.1.0 lib/torque/range.rb
torque-postgresql-2.0.6 lib/torque/range.rb
torque-postgresql-2.0.5 lib/torque/range.rb
torque-postgresql-2.0.4 lib/torque/range.rb
torque-postgresql-1.1.7 lib/torque/range.rb
torque-postgresql-2.0.3 lib/torque/range.rb
torque-postgresql-2.0.2 lib/torque/range.rb
torque-postgresql-1.1.6 lib/torque/range.rb
torque-postgresql-1.1.5 lib/torque/range.rb
torque-postgresql-2.0.1 lib/torque/range.rb
torque-postgresql-2.0.0 lib/torque/range.rb
torque-postgresql-1.1.4 lib/torque/range.rb
torque-postgresql-1.1.3 lib/torque/range.rb
torque-postgresql-1.1.2 lib/torque/range.rb
torque-postgresql-1.1.1 lib/torque/range.rb
torque-postgresql-1.1.0 lib/torque/range.rb