Class: Range

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_flux_capacitor/core_class_extensions.rb

Instance Method Summary collapse

Instance Method Details

#overlap(other_range) ⇒ Object

all of this added by jim cropcho:



33
34
35
36
# File 'lib/acts_as_flux_capacitor/core_class_extensions.rb', line 33

def overlap(other_range)
  return 0 unless self.overlaps?(other_range)
  ([self.first,other_range.first].max)..([self.last,other_range.last].min)
end

#overlaps?(other) ⇒ Boolean

Returns true if ranges overlap, false otherwise

Returns:

  • (Boolean)


27
28
29
# File 'lib/acts_as_flux_capacitor/core_class_extensions.rb', line 27

def overlaps? other
  include?(other.first) || other.include?(first)
end

#sizeObject Also known as: length



38
39
40
41
42
43
44
45
46
47
# File 'lib/acts_as_flux_capacitor/core_class_extensions.rb', line 38

def size
  if self.first.is_a?(Time) && self.last.is_a?(Time)
    time_size
  elsif self.first.is_a?(Fixnum) || self.first.is_a?(Float) && 
        self.last.is_a?(Fixnum)  || self.last.is_a?(Float)
    number_size
  else
    raise "size cannot handle these object types."
  end
end