Class: Vpim::Rrule::DaySet

Inherits:
Object
  • Object
show all
Defined in:
lib/vpim/rrule.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(ref) ⇒ DaySet

Returns a new instance of DaySet.



373
374
375
376
377
378
# File 'lib/vpim/rrule.rb', line 373

def initialize(ref)
  @ref = ref # Need to know because leap years have an extra day, and to get
               # our defaults.
  @month = nil
  @week = nil
end

Instance Method Details

#eachObject



431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/vpim/rrule.rb', line 431

def each
  @month  = { @ref.month => [ @ref.mday ] } if !@month
  @month.each_key do |m|
    @month[m] = [@ref.day] if !@month[m]
    # FIXME - if @ref.day is 31, and the month doesn't have 32 days, we'll
    # generate invalid dates here, check for that, and eliminate them
  end

  @month.keys.sort.each do |m|
    @month[m].sort.each do |d|
      yield m, d
    end
  end
end

#intersect_bymon(bymon) ⇒ Object

:nodoc:



392
393
394
395
396
397
398
399
400
401
# File 'lib/vpim/rrule.rb', line 392

def intersect_bymon(bymon) #:nodoc:
  if !@month
    @month = {}
    bymon.each do |m|
      @month[m] = nil
    end
  else
    @month.delete_if { |m, days| ! bymon.include? m }
  end
end

#intersect_dates(dates) ⇒ Object

:nodoc:



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/vpim/rrule.rb', line 403

def intersect_dates(dates) #:nodoc:
  return unless dates

  # If no months are in the dayset, add all the ones in dates
  if !@month
    @month = {}

    dates.each do |d|
      @month[d.mon] = nil
    end
  end

  # In each month,
  #   if there are days,
  #     eliminate those not in dates
  #   otherwise
  #     add all those in dates
  @month.each do |mon, days|
    days_in_mon = dates.find_all { |d| d.mon == mon }
    days_in_mon = days_in_mon.map { |d| d.day }

    if days
      days_in_mon = days_in_mon & days
    end
    @month[mon] = days_in_mon
  end
end

#mday=(pair) ⇒ Object



388
389
390
# File 'lib/vpim/rrule.rb', line 388

def mday=(pair)
  @month = { pair[0] => [ pair[1] ] }
end

#month=(mon) ⇒ Object



380
381
382
# File 'lib/vpim/rrule.rb', line 380

def month=(mon)
  @month = { mon => nil }
end

#week=(week) ⇒ Object



384
385
386
# File 'lib/vpim/rrule.rb', line 384

def week=(week)
  @week = week
end