Class: When::CalendarNote::Enumerator

Inherits:
Parts::Enumerator show all
Defined in:
lib/when_exe/calendarnote.rb

Overview

イベントを取得する Enumerator

Direct Known Subclasses

Week::Enumerator

Instance Attribute Summary

Attributes inherited from Parts::Enumerator

#count, #count_limit, #current, #direction, #exdate, #first, #index, #last, #object, #options, #parent, #processed

Instance Method Summary collapse

Methods inherited from Parts::Enumerator

_options, #_rewind, #each, #exclude_end, #has_next?, #next, #succ, #with_index, #with_object

Constructor Details

#initialize(parent, range, options) ⇒ Enumerator #initialize(parent, first, direction, options) ⇒ Enumerator

オブジェクトの生成

Overloads:

  • #initialize(parent, range, options) ⇒ Enumerator

    Parameters:

    Options Hash (options):

    • :event (String)

      イベント名

    • :count_limit (Integer)

      繰り返し回数(デフォルトは指定なし)

  • #initialize(parent, first, direction, options) ⇒ Enumerator

    Parameters:

    Options Hash (options):

    • :event (String)

      イベント名

    • :count_limit (Integer)

      繰り返し回数(デフォルトは指定なし)



655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
# File 'lib/when_exe/calendarnote.rb', line 655

def initialize(*args)
  if args[1].kind_of?(Range)
    parent, range, options = args
    first     = range.first
    last      = range.last
    direction = first < last ? :forward : :reverse
  else
    parent, first, direction, options = args
  end
  direction = options[:direction] if options[:direction]
  @parent = parent
  event   = options.delete(:event)
  case event
  when String ; void, @event, @parameter = event.split(/\A([^\d]+)/)
  else        ;       @event, @parameter = [parent.event, event]
  end
  @delta = @parent.send((@event+'_delta').to_sym, @parameter)
  instance_eval %Q{
    def event_eval(date)
      @parent.#{@event}(date, @parameter)
    end
  }
  date = event_eval(first)
  if direction == :reverse
    @delta = -@delta
    date   = event_eval(first + @delta) if first.to_i < date.to_i
  else
    date   = event_eval(first + @delta) if first.to_i > date.to_i
  end
  range ?
    super(@parent, range.exclude_end? ? date...last : date..last, options) :
    super(@parent, date, direction, options)
end

Instance Method Details

#_succWhen::TM::TemporalPosition

次のイベントを得る



630
631
632
# File 'lib/when_exe/calendarnote.rb', line 630

def _succ
  @current = (@current==:first) ? @first : event_eval(@current + @delta)
end