Class Runt::REWeek
In: lib/runt/temporalexpression.rb
Parent: Object

TExpr that matches days of the week within one week only.

If start and end day are equal, the entire week will match true.

 See also: Date

Methods

include?   new   to_s  

Included Modules

TExpr

Constants

VALID_RANGE = 0..6

Public Class methods

Creates a REWeek using the supplied start day(range = 0..6, where 0=>Sunday) and an optional end day. If an end day is not supplied, the maximum value (6 => Saturday) is assumed.

[Source]

# File lib/runt/temporalexpression.rb, line 391
  def initialize(start_day,end_day=6)
    validate(start_day,end_day)
    @start_day = start_day
    @end_day = end_day
  end

Public Instance methods

[Source]

# File lib/runt/temporalexpression.rb, line 397
  def include?(date)
    return true if all_week?
    if @start_day < @end_day
      @start_day<=date.wday && @end_day>=date.wday
    else
      (@start_day<=date.wday && 6 >=date.wday) || (0 <=date.wday && @end_day >=date.wday)
    end
  end

[Source]

# File lib/runt/temporalexpression.rb, line 406
  def to_s
    return "all week" if all_week?
    "#{Runt.day_name(@start_day)} through #{Runt.day_name(@end_day)}" 
  end

[Validate]