class MetalArchives::Range

Range which can start and/or end with nil

Attributes

begin[RW]

Begin- and endpoint of range

end[RW]

Begin- and endpoint of range

Public Class Methods

new(_begin = nil, _end = nil) click to toggle source

Create a new range

_begin

Start of range

Default: nil

_end

End of range

Default: nil

# File lib/metal_archives/utils/range.rb, line 27
def initialize(_begin = nil, _end = nil)
  @begin = _begin
  @end = _end
end

Public Instance Methods

<=>(other) click to toggle source

Comparison operator

# File lib/metal_archives/utils/range.rb, line 49
def <=>(other)
  comp_begin = self.begin <=> other.begin
  comp_end = self.end <=> other.end
  # Return nil if begin or end is uncomparable
  return nil if comp_begin.nil? || comp_end.nil?

  # Compare end if begin is equal
  return comp_end if comp_begin.zero?

  # Compare begin if end is equal
  return comp_begin if comp_begin.zero?

  # Compare actual range
  (self.end - self.begin) <=> (other.end - other.begin)
end
begin?() click to toggle source

Whether start of range is present

# File lib/metal_archives/utils/range.rb, line 35
def begin?
  !!@begin
end
end?() click to toggle source

Whether end of range is present

# File lib/metal_archives/utils/range.rb, line 42
def end?
  !!@end
end