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

Inherits:
When::V::Event::Enumerator::Logic show all
Defined in:
lib/when_exe/icalendar.rb

Overview

外部 Enumerator 用いた繰り返し

春分日、秋分日、復活祭などの指定に用いる

Instance Attribute Summary collapse

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

#by_part, #cash, #freq_index, #list

Instance Method Summary collapse

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

#_bound

Constructor Details

#initialize(by_part, list, position, ref, start, dtstart) ⇒ Enumerator

Returns a new instance of Enumerator.



1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
# File 'lib/when_exe/icalendar.rb', line 1629

def initialize(by_part, list, position, ref, start, dtstart)
  @by_part = by_part
  @ref =
    if ref
      When.Resource(ref, '_n:')
    else
      method = list[/\A[^-+\d]+/]
      if dtstart.frame.note.respond_to?(method)
        dtstart.frame.note
      else
        When.Resource(When::V::Event::RegisteredNotes[method], '_n:')
      end
    end
  @start   = start
  @list    = list.split(/,/).map {|w|
    raise ArgumentError, "The #{by_part} rule format error" unless w =~ /\A(([-+]?\d+)\*)?(.+?)([-+]\d+)?\z/
    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

#refObject (readonly)

Returns the value of attribute ref.



1597
1598
1599
# File 'lib/when_exe/icalendar.rb', line 1597

def ref
  @ref
end

#startObject (readonly)

Returns the value of attribute start.



1598
1599
1600
# File 'lib/when_exe/icalendar.rb', line 1598

def start
  @start
end

Instance Method Details

#_candidates(lower_bound, higher_bound) ⇒ Object



1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
# File 'lib/when_exe/icalendar.rb', line 1601

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, {:event=>spec})
    else
      enum = @ref.enum_for(higher_bound, :reverse, {:event=>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