Class: When::V::Event::Enumerator::Logic::Enumerator
- Inherits:
-
When::V::Event::Enumerator::Logic
- Object
- When::V::Event::Enumerator::Logic
- When::V::Event::Enumerator::Logic::Enumerator
- Defined in:
- lib/when_exe/icalendar.rb
Overview
外部 Enumerator 用いた繰り返し
春分日、秋分日、復活祭などの指定に用いる
Instance Attribute Summary collapse
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Attributes inherited from When::V::Event::Enumerator::Logic
#by_part, #cash, #freq_index, #list
Instance Method Summary collapse
- #_candidates(lower_bound, higher_bound) ⇒ Object
-
#initialize(by_part, list, position, ref, start) ⇒ Enumerator
constructor
A new instance of Enumerator.
Methods inherited from When::V::Event::Enumerator::Logic
Constructor Details
#initialize(by_part, list, position, ref, start) ⇒ Enumerator
Returns a new instance of Enumerator.
1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 |
# File 'lib/when_exe/icalendar.rb', line 1514 def initialize(by_part, list, position, ref, start) @by_part = by_part @ref = When.Resource(ref, '_n:') @start = start @list = list.split(/,/).map {|w| raise ArgumentError, "The #{by_part} rule format error" unless w =~ /^(([-+]?\d+)\*)?(.+?)([-+]\d+)?$/ nth, spec, period = $~[2..4] nth = (nth) ? nth.to_i : position period = When::TM::PeriodDuration.new((period||0).to_i, PostFreqIndex[@by_part]) [nth, spec, period] } end |
Instance Attribute Details
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
1482 1483 1484 |
# File 'lib/when_exe/icalendar.rb', line 1482 def ref @ref end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
1483 1484 1485 |
# File 'lib/when_exe/icalendar.rb', line 1483 def start @start end |
Instance Method Details
#_candidates(lower_bound, higher_bound) ⇒ Object
1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 |
# File 'lib/when_exe/icalendar.rb', line 1486 def _candidates(lower_bound, higher_bound) candidate = [] @list.each do |ord| nth, spec, period = ord shift = (period[PostFreqIndex[@by_part]] != 0) raise ArgumentError, "n*e+/-s format not permitted" if (nth || shift) && @freq_index >= When::DAY if (nth==nil || nth>0) enum = @ref.enum_for(lower_bound, :forward, spec) else enum = @ref.enum_for(higher_bound, :reverse, spec) end if (nth) date = nil nth.abs.times {date = enum.succ} date += period if shift candidate << date else enum.each do |date| date += period if shift break unless date < higher_bound candidate << date end end end return candidate end |