class Runt::REWeek
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
Constants
- VALID_RANGE
Attributes
end_day[R]
start_day[R]
Public Class Methods
new(start_day,end_day=6)
click to toggle source
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.
# File lib/runt/temporalexpression.rb, line 431 def initialize(start_day,end_day=6) validate(start_day,end_day) @start_day = start_day @end_day = end_day end
Public Instance Methods
==(o)
click to toggle source
Calls superclass method
# File lib/runt/temporalexpression.rb, line 437 def ==(o) o.is_a?(REWeek) ? start_day == o.start_day && end_day == o.end_day : super(o) end
include?(date)
click to toggle source
# File lib/runt/temporalexpression.rb, line 441 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
to_s()
click to toggle source
# File lib/runt/temporalexpression.rb, line 450 def to_s return "all week" if all_week? "#{Runt.day_name(@start_day)} through #{Runt.day_name(@end_day)}" end
Private Instance Methods
all_week?()
click to toggle source
# File lib/runt/temporalexpression.rb, line 457 def all_week? return true if @start_day==@end_day end
validate(start_day,end_day)
click to toggle source
# File lib/runt/temporalexpression.rb, line 461 def validate(start_day,end_day) unless VALID_RANGE.include?(start_day)&&VALID_RANGE.include?(end_day) raise ArgumentError, 'start and end day arguments must be in the range #{VALID_RANGE.to_s}.' end end