Parent

Included Modules

Runt::DateRange

DateRange

Based the range[http://martinfowler.com/ap2/range.html] pattern by Martin Fowler.

Author

Matthew Lipper

Constants

EMPTY

Attributes

end_expr[R]
start_expr[R]

Public Class Methods

new(start_expr, end_expr,exclusive=false) click to toggle source
# File lib/runt/daterange.rb, line 23
def initialize(start_expr, end_expr,exclusive=false)
  super(start_expr, end_expr,exclusive)
  @start_expr, @end_expr = start_expr, end_expr
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/runt/daterange.rb, line 61
def <=>(other)
  return @start_expr <=> other.start_expr if(@start_expr != other.start_expr)
  return @end_expr <=> other.end_expr
end
empty?() click to toggle source
# File lib/runt/daterange.rb, line 39
def empty?
  return @start_expr >= @end_expr
end
gap(obj) click to toggle source
# File lib/runt/daterange.rb, line 43
def gap(obj)

  return EMPTY if self.overlap? obj

  lower=nil
  higher=nil

  if((self<=>obj)<0)
    lower=self
    higher=obj
  else
    lower=obj
    higher=self
  end

  return DateRange.new((lower.end_expr+1),(higher.start_expr-1))
end
include?(obj) click to toggle source
# File lib/runt/daterange.rb, line 28
def include?(obj)
  return super(obj.min) && super(obj.max) if obj.kind_of? Range
  return super(obj)
end
max() click to toggle source
# File lib/runt/daterange.rb, line 67
def max; @end_expr  end
min() click to toggle source
# File lib/runt/daterange.rb, line 66
def min; @start_expr  end
overlap?(obj) click to toggle source
# File lib/runt/daterange.rb, line 33
def overlap?(obj)
  return true if( member?(obj) || include?(obj.min) || include?(obj.max) )
  return true if( obj.kind_of?(Range) && obj.include?(self) )
  false
end
to_s() click to toggle source
# File lib/runt/daterange.rb, line 68
def to_s; @start_expr.to_s + " " + @end_expr.to_s end

[Validate]

Generated with the Darkfish Rdoc Generator 2.