Class: GoogleCalendar::Calendar

Inherits:
Object
  • Object
show all
Defined in:
lib/when_exe/googlecalendar.rb

Overview

gcalapi の GoogleCalendar::Calendar クラスへの機能追加

Instance Method Summary collapse

Instance Method Details

#enum_for(conditions = {}) ⇒ Enumerator Also known as: to_enum

イベントを順に取り出す enumerator

Parameters:

  • conditions (Hash) (defaults to: {})

Options Hash (conditions):

Returns:

  • (Enumerator)


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/when_exe/googlecalendar.rb', line 81

def enum_for(conditions={})
  conditions['start-min'] ||= When.now
  conditions['sortorder'] ||= 'a'
  conditions['orderby']     = 'starttime'
  direction = (conditions['sortorder'] == 'd') ? :reverse : :forward
  first     = When.when?(conditions['start-min'])
  conditions['start-min']   = (When::Gregorian ^ first).to_s
  if conditions['start-max']
    last       = When.when?(conditions['start-max'])
    inner_args = [first...last]
    conditions['start-max'] = (When::Gregorian ^ last).to_s
  else
    inner_args = [first, direction]
  end

  confirmed = []
  canceled  = []
  self.events(conditions).each do |event|
    case event.event_status
    when 'canceled' ; canceled  << event
    else            ; confirmed << event
    end
  end
  outer_args = [first, direction]
  outer_args << {:exevent => canceled.map {|event| event.to_vevent}} if canceled.length > 0

  When::Parts::Enumerator::Integrated.new(self, confirmed.map {|event|
    event.to_vevent.enum_for(*inner_args)
  }, *outer_args)
end