Top Level Namespace

Defined Under Namespace

Modules: CalFilter Classes: DateTime, Time

Instance Method Summary collapse

Instance Method Details

#convert_to_icalendar(source) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/calfilter.rb', line 168

def convert_to_icalendar(source)
  case source
  when Icalendar::Calendar
    [source]
  when Array
    source
  when /^\s*BEGIN:VCALENDAR/m
    Icalendar.parse(source)
  else
    Icalendar.parse(open(source, 'r'))
  end
end

#convert_to_icalendars(sources) ⇒ Object



164
165
166
# File 'lib/calfilter.rb', line 164

def convert_to_icalendars(sources)
  sources.inject([]){|accum, source| accum += convert_to_icalendar(source)}
end

#filter_calendars(*sources, &block) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/calfilter.rb', line 146

def filter_calendars(*sources, &block)
  cals = convert_to_icalendars(sources)
  return cals unless block_given?
  actions = cals.map do |cal| 
    wrapper = CalFilter.wrap_calendar(cal)
    catch(:bailout) do
      yield wrapper
    end
    wrapper.__action__
  end
  new_cals = CalFilter::keep_or_delete_items(cals, 'calendars', actions)
  os = CalFilter.output_stream
  unless os.nil?
    new_cals.each{|cal| os.puts cal.to_ical}
  end
  new_cals
end