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.



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

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



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

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:



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

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:



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
430
# File 'lib/vpim/rrule.rb', line 404

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



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

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

#month=(mon) ⇒ Object



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

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

#week=(week) ⇒ Object



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

def week=(week)
  @week = week
end