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.



1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
# File 'lib/when_exe/icalendar.rb', line 1694

def initialize(by_part, list)
  @by_part = by_part
  @list    = list.split(/,/).map {|w|
    raise ArgumentError, "The BYDAY rule format error" unless w =~ /\A([-+]?\d+)?(MO|TU|WE|TH|FR|SA|SU)([-+]\d+)?\z/
    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