Class: Runt::REWeek
- Inherits:
-
Object
- Object
- Runt::REWeek
- Includes:
- TExpr
- Defined in:
- lib/runt/temporalexpression.rb
Overview
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
Constant Summary collapse
- VALID_RANGE =
0..6
Instance Attribute Summary collapse
-
#end_day ⇒ Object
readonly
Returns the value of attribute end_day.
-
#start_day ⇒ Object
readonly
Returns the value of attribute start_day.
Instance Method Summary collapse
- #==(o) ⇒ Object
- #include?(date) ⇒ Boolean
-
#initialize(start_day, end_day = 6) ⇒ REWeek
constructor
Creates a REWeek using the supplied start day(range = 0..6, where 0=>Sunday) and an optional end day.
- #to_s ⇒ Object
Methods included from TExpr
#&, #-, #and, #dates, #minus, #or, #|
Constructor Details
#initialize(start_day, end_day = 6) ⇒ REWeek
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.
431 432 433 434 435 |
# 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 |
Instance Attribute Details
#end_day ⇒ Object (readonly)
Returns the value of attribute end_day.
425 426 427 |
# File 'lib/runt/temporalexpression.rb', line 425 def end_day @end_day end |
#start_day ⇒ Object (readonly)
Returns the value of attribute start_day.
425 426 427 |
# File 'lib/runt/temporalexpression.rb', line 425 def start_day @start_day end |
Instance Method Details
#==(o) ⇒ Object
437 438 439 |
# 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) ⇒ Boolean
441 442 443 444 445 446 447 448 |
# 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 |