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.
1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 |
# File 'lib/when_exe/icalendar.rb', line 1477 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.
1445 1446 1447 |
# File 'lib/when_exe/icalendar.rb', line 1445 def ref @ref end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
1446 1447 1448 |
# File 'lib/when_exe/icalendar.rb', line 1446 def start @start end |
Instance Method Details
#_candidates(lower_bound, higher_bound) ⇒ Object
1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 |
# File 'lib/when_exe/icalendar.rb', line 1449 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 |