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/range.rb, line 28
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/range.rb, line 50
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?

  return nil unless self.begin.is_a?(Integer) && self.end.is_a?(Integer)
  return nil unless other.begin.is_a?(Integer) && other.end.is_a?(Integer)

  # 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/range.rb, line 36
def begin?
  !@begin.nil?
end
end?() click to toggle source

Whether end of range is present

# File lib/metal_archives/range.rb, line 43
def end?
  !@end.nil?
end