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



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

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



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

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

#encodeObject

TODO - BY.…



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

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



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

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



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

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