Class: TExp::DayOfWeekInterval
- Inherits:
-
And
show all
- Defined in:
- lib/texp/day_of_week_interval.rb
Instance Method Summary
collapse
Methods inherited from And
#encode, #includes?
#each, parse_callback
Methods inherited from Base
#*, #+, #-, #-@, #each, #first_day_of_window, #include?, #last_day_of_window, parse_callback, register_parse_callback, #to_s, #window
Constructor Details
Returns a new instance of DayOfWeekInterval.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/texp/day_of_week_interval.rb', line 6
def initialize(*args)
if args.size == 3
day, week_interval, start_date = args[0..2]
@day_texp = DayOfWeek.new(day)
@week_interval_texp = WeekInterval.new(
find_day_of_week_on_or_after(start_date, day),
week_interval
)
super(@day_texp, @week_interval_texp)
else
@day_texp, @week_interval_texp = args[0], args[1]
super(@day_texp, @week_interval_texp)
end
end
|
Instance Method Details
#find_day_of_week_on_or_after(date, day_of_week) ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/texp/day_of_week_interval.rb', line 21
def find_day_of_week_on_or_after(date, day_of_week)
raise ArgumentError, "#{day_of_week} is not a valid day of week" unless
(0..6).to_a.include? day_of_week
while date.wday != day_of_week
date = date + 1
end
date
end
|
#inspect ⇒ Object
34
35
36
|
# File 'lib/texp/day_of_week_interval.rb', line 34
def inspect
"#{@week_interval_texp.inspect} #{@day_texp.inspect}"
end
|
#reanchor(date) ⇒ Object
30
31
32
|
# File 'lib/texp/day_of_week_interval.rb', line 30
def reanchor(date)
super(find_day_of_week_on_or_after(date, @day_texp.days[0]))
end
|