Class: When::V::Event::Enumerator::Logic::Weekday

Inherits:
Residue show all
Defined in:
lib/when_exe/icalendar.rb

Overview

BYWEEKDAY(=BYDAY)を実装

Instance Attribute Summary

Attributes inherited from When::V::Event::Enumerator::Logic

#by_part, #cash, #freq_index, #list

Instance Method Summary collapse

Methods inherited from Residue

#_candidates

Methods inherited from When::V::Event::Enumerator::Logic

#_bound, #_candidates

Constructor Details

#initialize(by_part, list) ⇒ Weekday

Returns a new instance of Weekday.



1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
# File 'lib/when_exe/icalendar.rb', line 1568

def initialize(by_part, list)
  @by_part = by_part
  @list    = list.split(/,/).map {|w|
    raise ArgumentError, "The BYDAY rule format error" unless w =~ /^([-+]?\d+)?(MO|TU|WE|TH|FR|SA|SU)([-+]\d+)?$/
    nth, spec, period = $~[1..3]
    if nth
      nth = nth.to_i
      nth = (nth>0) ? nth-1 : nth
    end
    residue = When::Coordinates::Residue.day_of_week(spec) >> (nth||0)
    [nth, residue, When::TM::PeriodDuration.new([0,0,(period||0).to_i])]
  }
end