Class: Vpim::Rrule::Maker

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

Overview

Help encode an RRULE value.

TODO - the Maker is both incomplete, and its a bit cheesy, I’d like to do something that is a kind of programmatic version of the UI that iCal has.

Constant Summary collapse

FREQ =

:nodoc: incomplete!

%w{ YEARLY WEEKLY MONTHLY DAILY }

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Maker

:yield: self



530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/vpim/rrule.rb', line 530

def initialize(&block) #:yield: self
  @freq = nil
  @until = nil
  @count = nil
  @interval = nil
  @wkst = nil
  @by = {}

  if block
    yield self
  end
end

Instance Method Details

#count=(rcount) ⇒ Object

count is integral



562
563
564
565
566
567
# File 'lib/vpim/rrule.rb', line 562

def count=(rcount)
  if @until
    raise ArgumentError, "Cannot specify COUNT if UNTIL was specified"
  end
  @count = rcount.to_int
end

#encodeObject

TODO - BY.…



571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
# File 'lib/vpim/rrule.rb', line 571

def encode
  unless @freq
    raise ArgumentError, "Must specify FREQUENCY"
  end

  rrule = "FREQ=#{@freq}"

  [
    ["COUNT", @count],
    ["UNTIL", @until],
    # TODO...
  ].each do |k,v|
    if v
      rrule += ";#{k}=#{v}"
    end
  end
  rrule
end

#frequency=(freq) ⇒ Object



545
546
547
548
549
550
551
# File 'lib/vpim/rrule.rb', line 545

def frequency=(freq)
  freq = freq.to_str.upcase
  unless FREQ.include? freq
    raise ArgumentError, "Frequency #{freq} is not valid"
  end
  @freq = freq
end

#until=(runtil) ⇒ Object

runtil is Time, Date, or DateTime



554
555
556
557
558
559
# File 'lib/vpim/rrule.rb', line 554

def until=(runtil)
  if @count
    raise ArgumentError, "Cannot specify UNTIL if COUNT was specified"
  end
  @until = runtil
end