Sha256: ec4302c5b2a88df834a7ad5c98b199ccb2b52e3ff73d60a0c8e193fdfb07e327

Contents?: true

Size: 752 Bytes

Versions: 4

Compression:

Stored size: 752 Bytes

Contents

# encoding: utf-8

# Extend Range with methods to normalize and find overlapping ranges
class Range

  # Returns an inclusive Range
  #
  # @example
  #   inclusive = range.to_inclusive
  #
  # @return [Range]
  #
  # @api public
  def to_inclusive
    if exclude_end?
      self.class.new(first, last.pred)
    else
      self
    end
  end unless method_defined? :to_inclusive

  # Compare the range with another range to see if they overlap
  #
  # @example
  #   range.overlaps?(other)  # => true or false
  #
  # @param [Range] other
  #   the other Range to compare with
  #
  # @return [Boolean]
  #
  # @api public
  def overlaps?(other)
    cover?(other.first) || other.cover?(first)
  end unless method_defined? :overlaps?

end # class Range

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
veritas-0.0.7 lib/veritas/core_ext/range.rb
veritas-0.0.6 lib/veritas/core_ext/range.rb
veritas-0.0.5 lib/veritas/core_ext/range.rb
veritas-0.0.4 lib/veritas/core_ext/range.rb