Class: When::V::Event

Inherits:
Root show all
Extended by:
Parts::Resource::Pool
Defined in:
lib/when_exe/icalendar.rb,
lib/when_exe/icalendar.rb,
lib/when_exe/googlecalendar.rb

Overview

Eventを定義する

BEGIN:VEVENT...END:VEVENT のブロックに対応

Direct Known Subclasses

Alarm, Freebusy, Journal, TimezoneProperty, Todo

Defined Under Namespace

Classes: Enumerator

Constant Summary collapse

Properties =
[['dtstamp', 'uid', 'dtstart'], [],
                 ['class', 'created', 'description', 'geo',
'last_modified', 'location', 'organizer', 'priority',
'seq', 'status', 'summary', 'transp',
'url', 'recurid', 'dtend', 'duration'], [],
                 ['rrule',
'attach', 'attendee', 'categories', 'comment', 'contact',
'exdate', 'exevent', 'rstatus', 'related',
'resources', 'rdate']]
Classes =
[Root, Alarm]

Constants inherited from Root

Root::AwareProperties, Root::DefaultOptional, Root::DefaultUnique

Constants included from Parts::Resource

Parts::Resource::LabelProperty, Parts::Resource::Prefix, Parts::Resource::PrefixIndex, Parts::Resource::PrefixKeys, Parts::Resource::PrefixValues

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from Root

#calscale, #property

Attributes included from Parts::Resource

#_pool, #child, #keys, #locale, #namespace

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parts::Resource::Pool

[], []=, _pool, _setup_, pool_keys

Methods included from Parts::Resource::Synchronize

#synchronize

Methods inherited from Root

#_enumerator, #include?

Methods inherited from BasicTypes::Object

#tap

Methods included from Parts::Resource

#[], #^, _extract_prefix, _instance, _parse, _path_with_prefix, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #next, #parent, #prev, #registered?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class When::Parts::Resource

Class Attribute Details

.default_untilWhen::TM::IntervalLength (readonly)

最大打ち切り時間



497
498
499
# File 'lib/when_exe/icalendar.rb', line 497

def default_until
  @default_until
end

Instance Attribute Details

#dtendWhen::TM::TemporalPosition, When::Parts::GeometricComplex (readonly)

DTEND Property



539
540
541
# File 'lib/when_exe/icalendar.rb', line 539

def dtend
  @dtend
end

#dtstartWhen::TM::TemporalPosition, When::Parts::GeometricComplex (readonly)

DTSTART Property



533
534
535
# File 'lib/when_exe/icalendar.rb', line 533

def dtstart
  @dtstart
end

#durationWhen::TM::Duration (readonly)

Note:

DTSTART Property が保持する When::TM::TemporalPosition の分解能で識別できない 時間差はイベント継続中とみなすので、例えば分解能が DAY の場合、DURATION Porperty に When.Duration(‘P1D’)と指定する必要はない。 DTEND Property が指定された場合、DURATION Property に変換して保持する。

DURATION Property

Returns:



551
552
553
# File 'lib/when_exe/icalendar.rb', line 551

def duration
  @duration
end

#exdateWhen::Parts::GeometricComplex (readonly)

EXDATE Property



557
558
559
# File 'lib/when_exe/icalendar.rb', line 557

def exdate
  @exdate
end

#first_occurrenceString (readonly)

Note:

RFC 5545 では ‘Include’ となっているが、それ以外の振る舞いが可能なように拡張。

DTSTART Property を first occurrence とするか

Returns:

  • (String)
    ‘Include’ - first occurrence とする
    ‘Exclude’ - first occurrence しない
    それ以外 - RRULE により該当する場合に first occurrence とする


581
582
583
# File 'lib/when_exe/icalendar.rb', line 581

def first_occurrence
  @first_occurrence
end

#rdateArray<When::TM::TemporalPosition, When::Parts::GeometricComplex> (readonly)

Note:

RRULE の COUNT が指定されている場合、後で途中の系列を抜き出すような指定をされても よいように、Enumerator 生成時にCOUNT分の計算をして RDATE Property に登録する。 このため、COUNTに大きな値を指定すると、Enumerator 生成に予想外の時間がかかることが ある。

RDATE Property



569
570
571
# File 'lib/when_exe/icalendar.rb', line 569

def rdate
  @rdate
end

#rruleHash (readonly)

Note:

iCalendar の RRULE を Hash に展開したものを保持している。 RRULE は、年のサイクルや7日以外の日のサイクルおよび夏時間の切り替えを 扱えるように RFC 5545 から拡張されている。

RRULE Property

Returns:

  • (Hash)


527
528
529
# File 'lib/when_exe/icalendar.rb', line 527

def rrule
  @rrule
end

Class Method Details

._setup_(default_until = nil) ⇒ Object

Note:

RRULE の条件が成立しない場合に無限ループにおちいることを避けるため 他に指定がなくとも、計算を打ち切るようにしている。その打ち切り時間 (When.now + default_until)を本メソッドで指定している。 default_until の指定がない場合、default_until は 1000年と解釈する。

When::V::Event Class のグローバルな設定を行う

Parameters:



509
510
511
512
513
514
515
# File 'lib/when_exe/icalendar.rb', line 509

def _setup_(default_until=nil)
  @_lock_ = Mutex.new if When.multi_thread
  @_lock_.lock if @_lock_
  @_pool = {}
  @default_until = default_until
  @_lock_.unlock if @_lock_
end

Instance Method Details

#_enumerator_list(args) ⇒ Object



641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
# File 'lib/when_exe/icalendar.rb', line 641

def _enumerator_list(args)
  options = args[-1]
  rdate = @rdate.dup
  options[:exdate]  = @exdate.dup if @exdate
  options[:exevent] = @exevent.map {|v| self[v]} if @exevent
  case (options['1st'] || @first_occurrence).capitalize
  when 'Include' ; rdate.unshift(@duration ? When::Parts::GeometricComplex.new(@dtstart, @duration) : @dtstart)
  when 'Exclude' ; options[:exdate] |= @dtstart
  end

  # 配下の Enumerator の初期化
  enumerators = []
  @rrule.each do |rrule|
    if @due && !(rrule['UNTIL'] && rrule['UNTIL'] <= @due)
      rrule = rrule.dup
      rrule['UNTIL'] = @due
    end
    if rrule['COUNT']
      Event::Enumerator.new(self, rrule, @dtstart, @duration, @dtstart, options).each {|date| rdate << date }
    else
      enumerators << Event::Enumerator.new(self, rrule, @dtstart, @duration, *args)
    end
  end

  enumerators.unshift(When::Parts::Enumerator::Array.new(self, rdate, *args[1..-1])) if (rdate.length > 0)

  return enumerators
end

#dtstopWhen::TM::TemporalPosition, When::Parts::GeometricComplex

Note:

無限に続く可能性がある場合、When::TimeValue::Max(+Infinity)

最後のイベント



598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
# File 'lib/when_exe/icalendar.rb', line 598

def dtstop
  return @dtstop if (@dtstop)

  @dtstop = @dtstart
  @rdate.each do |date|
    @dtstop = date if (date > @dtstop)
  end
  @rrule.each do |rrule|
    unless (rrule['UNTIL'])
      @dtstop = When::TimeValue::Max
      break
    end
    @dtstop = rrule['UNTIL'] if (rrule['UNTIL'] > @dtstop)
  end
  return @dtstop
end

#initializeEnumerator #initialize(range, count_limit = nil) ⇒ Enumerator #initialize(first, direction, count_limit) ⇒ Enumerator

Note:

block が与えられている場合、yield する。

順次実行

Overloads:

  • #initialize(range, count_limit = nil) ⇒ Enumerator

    Parameters:

    • range (Range, When::Parts::GeometricComplex)

      始点-range.first, 終点-range.last

    • count_limit (Integer) (defaults to: nil)

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

  • #initialize(first, direction, count_limit) ⇒ Enumerator

    Parameters:

    • first (When::TM::TemporalPosition)

      始点

    • direction (Symbol)

      :forward - 昇順, :reverse - 降順

    • count_limit (Integer)

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

Returns:



632
633
634
635
636
637
638
# File 'lib/when_exe/icalendar.rb', line 632

def each(*args, &block)
  if args.length > 0
    super
  else
    super(@dtstart, &block)
  end
end

#labelString

ユニーク識別名 - UID Property をユニーク識別名とする。

Returns:



587
588
589
# File 'lib/when_exe/icalendar.rb', line 587

def label
  @property['uid'].object
end

#to_gcalevent(cal) ⇒ GoogleCalendar::Event Also known as: gcalevent

GoogleCalendar::Event オブジェクトへの変換

Parameters:

Returns:



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/when_exe/googlecalendar.rb', line 120

def to_gcalevent(cal)
  event = cal.create_event
  event.title = summary     if respond_to?(:summary)
  event.desc  = description if respond_to?(:description)
  event.where = location    if respond_to?(:location)
  if rrule.size == 0
    event.st  = dtstart.to_time
    event.en  = dtend.to_time
  else
    event.recurrence =
      (['RRULE:' + property['rrule'][0].object] +
       ['dtstart', 'dtend'].map {|key|
         value = property[key].attribute['.']
         key.upcase + (value =~ /=/ ? ';' : ':') + value
       }).join("\n") + "\n"
  end
  event
end