Class: Range
- Inherits:
-
Object
- Object
- Range
- Extended by:
- FatCore::Range::ClassMethods
- Includes:
- FatCore::Range
- Defined in:
- lib/fat_core/range.rb
Sorting collapse
-
.overlaps_among?(ranges) ⇒ Boolean
extended
from FatCore::Range::ClassMethods
Return whether any of the
ranges
overlap one another. -
#<=>(other) ⇒ -1, ...
included
from FatCore::Range
Compare this range with other first by min values, then by max values.
Queries collapse
-
#contiguous?(other) ⇒ Boolean
included
from FatCore::Range
Is self contiguous to other either on the left or on the right? First, the two ranges are sorted by their min values, and the range with the lowest min value is considered to be on the "left" and the other range on the "right".
-
#left_contiguous?(other) ⇒ Boolean
included
from FatCore::Range
Is self on the left of and contiguous to other? Whether one range is "contiguous" to another has two cases:.
-
#overlaps?(other) ⇒ Boolean
included
from FatCore::Range
Return whether self overlaps with other Range.
-
#overlaps_among?(ranges) ⇒ Boolean
included
from FatCore::Range
Return whether any of the
ranges
that overlap self have overlaps among one another. -
#proper_subset_of?(other) ⇒ Boolean
included
from FatCore::Range
Return whether self is contained within
other
range, without their boundaries touching. -
#proper_superset_of?(other) ⇒ Boolean
included
from FatCore::Range
Return whether self contains
other
range, without their boundaries touching. -
#right_contiguous?(other) ⇒ Boolean
included
from FatCore::Range
Is self on the right of and contiguous to other? Whether one range is "contiguous" to another has two cases:.
-
#spanned_by?(ranges) ⇒ Boolean
included
from FatCore::Range
Return true if the given ranges collectively cover this range without overlaps and without gaps.
-
#subset_of?(other) ⇒ Boolean
included
from FatCore::Range
Return whether self is contained within
other
range, even if their boundaries touch. -
#superset_of?(other) ⇒ Boolean
included
from FatCore::Range
Return whether self contains
other
range, even if their boundaries touch.
Operations collapse
-
#difference(other) ⇒ Object
(also: #-)
included
from FatCore::Range
The difference method, -, removes the overlapping part of the other argument from self.
-
#gaps(ranges) ⇒ Array<Range>
included
from FatCore::Range
If this range is not spanned by the
ranges
collectively, return an Array of ranges representing the gaps in coverage. -
#intersection(other) ⇒ Range?
(also: #&)
included
from FatCore::Range
Return a Range that represents the intersection between this range and the
other
range. -
#join(other) ⇒ Range?
included
from FatCore::Range
Return a range that concatenates this range with other if it is contiguous with this range on the left or right; return nil if the ranges are not contiguous.
-
#overlaps(ranges) ⇒ Array<Range>
included
from FatCore::Range
Within this range return an Array of Ranges representing the overlaps among the given Array of Ranges
ranges
. -
#tex_quote ⇒ String
included
from FatCore::Range
Allow erb or erubis documents to directly interpolate a Range.
-
#union(other) ⇒ Range?
(also: #+)
included
from FatCore::Range
Return a Range that represents the union between this range and the
other
range.
Class Method Details
permalink .overlaps_among?(ranges) ⇒ Boolean Originally defined in module FatCore::Range::ClassMethods
Return whether any of the ranges
overlap one another
Instance Method Details
permalink #<=>(other) ⇒ -1, ... Originally defined in module FatCore::Range
Compare this range with other first by min values, then by max values.
This causes a sort of Ranges with Comparable elements to sort from left to right on the number line, then for Ranges that start on the same number, from smallest to largest.
permalink #contiguous?(other) ⇒ Boolean Originally defined in module FatCore::Range
Is self contiguous to other either on the left or on the right? First, the two ranges are sorted by their min values, and the range with the lowest min value is considered to be on the "left" and the other range on the "right". Whether one range is "contiguous" to another then has two cases:
- If the max element of the Range on the left respond to the #succ method (that is, its value is a discrete value such as Integer or Date) test whether the succ to the max value of the Range on the left is equal to the min value of the Range on the right.
- If the max element of the Range on the left does not respond to the #succ method (that is, its values are continuous values such as Floats) test whether the max value of the Range on the left is equal to the min value of the Range on the right
permalink #difference(other) ⇒ Object Also known as: - Originally defined in module FatCore::Range
The difference method, -, removes the overlapping part of the other argument from self. Because in the case where self is a superset of the other range, this will result in the difference being two non-contiguous ranges, this returns an array of ranges. If there is no overlap or if self is a subset of the other range, return an array of self
permalink #gaps(ranges) ⇒ Array<Range> Originally defined in module FatCore::Range
If this range is not spanned by the ranges
collectively, return an Array
of ranges representing the gaps in coverage. The ranges
can over-cover
this range on the left or right without affecting the result, that is,
each range in the returned array of gap ranges will always be subsets of
this range.
If the ranges
span this range, return an empty array.
permalink #intersection(other) ⇒ Range? Also known as: & Originally defined in module FatCore::Range
Return a Range that represents the intersection between this range and the
other
range. If there is no intersection, return nil.
permalink #join(other) ⇒ Range? Originally defined in module FatCore::Range
Return a range that concatenates this range with other if it is contiguous with this range on the left or right; return nil if the ranges are not contiguous.
permalink #left_contiguous?(other) ⇒ Boolean Originally defined in module FatCore::Range
Is self on the left of and contiguous to other? Whether one range is "contiguous" to another has two cases:
- If the elements of the Range on the left respond to the #succ method (that is, its values are discrete values such as Integers or Dates) test whether the succ to the max value of the Range on the left is equal to the min value of the Range on the right.
- If the elements of the Range on the left do not respond to the #succ method (that is, its values are continuous values such as Floats) test whether the max value of the Range on the left is equal to the min value of the Range on the right
permalink #overlaps(ranges) ⇒ Array<Range> Originally defined in module FatCore::Range
Within this range return an Array of Ranges representing the overlaps
among the given Array of Ranges ranges
. If there are no overlaps, return
an empty array. Don't consider overlaps in the ranges
that occur outside
of self.
permalink #overlaps?(other) ⇒ Boolean Originally defined in module FatCore::Range
Return whether self overlaps with other Range.
permalink #overlaps_among?(ranges) ⇒ Boolean Originally defined in module FatCore::Range
Return whether any of the ranges
that overlap self have overlaps among one
another.
This does the same thing as Range.overlaps_among?
, except that it filters
the ranges
to only those overlapping self before testing for overlaps
among them.
permalink #proper_subset_of?(other) ⇒ Boolean Originally defined in module FatCore::Range
Return whether self is contained within other
range, without their
boundaries touching.
permalink #proper_superset_of?(other) ⇒ Boolean Originally defined in module FatCore::Range
Return whether self contains other
range, without their
boundaries touching.
permalink #right_contiguous?(other) ⇒ Boolean Originally defined in module FatCore::Range
Is self on the right of and contiguous to other? Whether one range is "contiguous" to another has two cases:
- If the elements of the Range on the left respond to the #succ method (that is, its values are discrete values such as Integers or Dates) test whether the succ to the max value of the Range on the left is equal to the min value of the Range on the right.
- If the elements of the Range on the left do not respond to the #succ method (that is, its values are continuous values such as Floats) test whether the max value of the Range on the left is equal to the min value of the Range on the right
permalink #spanned_by?(ranges) ⇒ Boolean Originally defined in module FatCore::Range
Return true if the given ranges collectively cover this range without overlaps and without gaps.
permalink #subset_of?(other) ⇒ Boolean Originally defined in module FatCore::Range
Return whether self is contained within other
range, even if their
boundaries touch.
permalink #superset_of?(other) ⇒ Boolean Originally defined in module FatCore::Range
Return whether self contains other
range, even if their
boundaries touch.
permalink #tex_quote ⇒ String Originally defined in module FatCore::Range
Allow erb or erubis documents to directly interpolate a Range.
permalink #union(other) ⇒ Range? Also known as: + Originally defined in module FatCore::Range
Return a Range that represents the union between this range and the
other
range. If there is no overlap and self is not contiguous with
other
, return nil
.