Class: PowerRanger::Range

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/power_ranger/range.rb

Instance Method Summary collapse

Constructor Details

#initialize(range) ⇒ Range

Returns a new instance of Range.


10
11
12
# File 'lib/power_ranger/range.rb', line 10

def initialize(range)
  @range = range
end

Instance Method Details

#after?(other) ⇒ Boolean Also known as: >

Returns:

  • (Boolean)

33
34
35
# File 'lib/power_ranger/range.rb', line 33

def after?(other)
  first > other.last
end

#before?(other) ⇒ Boolean Also known as: <

Returns:

  • (Boolean)

29
30
31
# File 'lib/power_ranger/range.rb', line 29

def before?(other)
  last < other.first
end

#during?(other) ⇒ Boolean

Returns:

  • (Boolean)

40
41
42
# File 'lib/power_ranger/range.rb', line 40

def during?(other)
  first >= other.first && last <= other.last
end

#equal?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)

44
45
46
# File 'lib/power_ranger/range.rb', line 44

def equal?(other)
  first == other.first && last == other.last
end

#finishes?(other) ⇒ Boolean

Returns:

  • (Boolean)

54
55
56
# File 'lib/power_ranger/range.rb', line 54

def finishes?(other)
  first >= other.first && last == other.last
end

#join(other) ⇒ Range Also known as: +

Join two ranges

Returns:


17
18
19
20
21
22
23
24
25
# File 'lib/power_ranger/range.rb', line 17

def join(other)
  return self if other.during?(self)
  return other if self.during?(other)

  return [self, other] if before?(other)
  return [other, self] if after?(other)

  self
end

#starts?(other) ⇒ Boolean

Returns:

  • (Boolean)

50
51
52
# File 'lib/power_ranger/range.rb', line 50

def starts?(other)
  first == other.first && last <= other.last
end

#to_rangeObject


58
59
60
# File 'lib/power_ranger/range.rb', line 58

def to_range
  @range
end