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/google_api.rb,
lib/when_exe/obsolete/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::ConstList, Parts::Resource::ConstTypes, Parts::Resource::IRIDecode, Parts::Resource::IRIDecodeTable, Parts::Resource::IRIEncode, Parts::Resource::IRIEncodeTable, Parts::Resource::IRIHeader, Parts::Resource::LabelProperty

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 included from Parts::Resource

#[], #^, _abbreviation_to_iri, _decode, _encode, _extract_prefix, _instance, _instantiate, _parse, _path_with_prefix, _replace_tags, _simplify_path, base_uri, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #next, #parent, #prev, #registered?, root_dir

Dynamic Method Handling

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

Instance Attribute Details

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

DTEND Property



597
598
599
# File 'lib/when_exe/icalendar.rb', line 597

def dtend
  @dtend
end

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

DTSTART Property



591
592
593
# File 'lib/when_exe/icalendar.rb', line 591

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



609
610
611
# File 'lib/when_exe/icalendar.rb', line 609

def duration
  @duration
end

#exdateWhen::Parts::GeometricComplex (readonly)

EXDATE Property



615
616
617
# File 'lib/when_exe/icalendar.rb', line 615

def exdate
  @exdate
end

#first_occurrenceString (readonly)

Note:

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

DTSTART Property を first occurrence とするか



639
640
641
# File 'lib/when_exe/icalendar.rb', line 639

def first_occurrence
  @first_occurrence
end

#google_api_propsHash (readonly)

イベントのプロパティ



103
104
105
# File 'lib/when_exe/google_api.rb', line 103

def google_api_props
  @google_api_props
end

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

Note:

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

RDATE Property



627
628
629
# File 'lib/when_exe/icalendar.rb', line 627

def rdate
  @rdate
end

#rruleHash (readonly)

Note:

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

RRULE Property



585
586
587
# File 'lib/when_exe/icalendar.rb', line 585

def rrule
  @rrule
end

#summaryString, When::BasicTypes::M17n (readonly)

SUMMARY Property



574
575
576
# File 'lib/when_exe/icalendar.rb', line 574

def summary
  @summary
end

Class Method Details

._setup_(default_until = nil) ⇒ Object

Note:

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

Note:

本メソッドでマルチスレッド対応の管理変数の初期化を行っている。このため、本メソッド自体はスレッドセーフでない。

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



548
549
550
551
552
# File 'lib/when_exe/icalendar.rb', line 548

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

._setup_infoHash

設定情報を取得する



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

def _setup_info
  {:until => default_until}
end

.default_untilWhen::TM::IntervalLength

最大打ち切り時間



565
566
567
# File 'lib/when_exe/icalendar.rb', line 565

def default_until
  @default_until ||= 1000*When::TM::Duration::YEAR
end

.gcal2ical(gprops) ⇒ Hash

GoogleCalendar のプロパティを iCalendar のプロパティに変換する



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/when_exe/google_api.rb', line 113

def gcal2ical(gprops)
  iprops = {}
  gprops.each_pair do |key, value|
    case key
    when 'summary'
      iprops['summary'] = value
    when 'start', 'end'
      date  = 'VALUE=DATE'
      date += '-TIME' if value.key?('dateTime')
      date += ';TZID=' + value['timeZone'] if value.key?('timeZone')
      date += ':' + (value['date'] || value['dateTime'])
      iprops['dt' + key] = date
    when 'recurrence'
      value.map do |line|
        tag, rule = line.split(':', 2)
        tag.downcase!
        if iprops.key?(tag)
          iprops[tag] = Array(iprops[tag]) + [rule]
        else
          iprops[tag] = rule
        end
      end
    when 'iCalUID'
      iprops['uid'] = value
    end
  end
  iprops
end

Instance Method Details

#_enumerator_list(args) ⇒ Object



699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
# File 'lib/when_exe/icalendar.rb', line 699

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)

最後のイベント



656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
# File 'lib/when_exe/icalendar.rb', line 656

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

#eachEnumerator #each(range, count_limit = nil) ⇒ Enumerator #each(first, direction, count_limit) ⇒ Enumerator

Note:

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

順次実行



690
691
692
693
694
695
696
# File 'lib/when_exe/icalendar.rb', line 690

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

#labelString

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



645
646
647
# File 'lib/when_exe/icalendar.rb', line 645

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

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

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



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/when_exe/obsolete/googlecalendar.rb', line 124

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