class IceCube::IcalBuilder

Constants

ICAL_DAYS

Public Class Methods

fixnum_to_ical_day(num) click to toggle source
# File lib/ice_cube/builders/ical_builder.rb, line 11
def self.fixnum_to_ical_day(num)
  ICAL_DAYS[num]
end
ical_duration(duration) click to toggle source
# File lib/ice_cube/builders/ical_builder.rb, line 47
def self.ical_duration(duration)
  hours = duration / 3600; duration %= 3600
  minutes = duration / 60; duration %= 60
  repr = ''
  repr << "#{hours}H" if hours > 0
  repr << "#{minutes}M" if minutes > 0
  repr << "#{duration}S" if duration > 0
  "PT#{repr}"
end
ical_format(time, force_utc) click to toggle source
# File lib/ice_cube/builders/ical_builder.rb, line 38
def self.ical_format(time, force_utc)
  time = time.dup.utc if force_utc
  if time.utc?
    ":#{IceCube::I18n.l(time, format: '%Y%m%dT%H%M%SZ')}" # utc time
  else
    ";TZID=#{IceCube::I18n.l(time, format: '%Z:%Y%m%dT%H%M%S')}" # local time specified
  end
end
ical_utc_format(time) click to toggle source
# File lib/ice_cube/builders/ical_builder.rb, line 33
def self.ical_utc_format(time)
  time = time.dup.utc
  IceCube::I18n.l(time, format: '%Y%m%dT%H%M%SZ') # utc time
end
new() click to toggle source
# File lib/ice_cube/builders/ical_builder.rb, line 7
def initialize
  @hash = {}
end

Public Instance Methods

[](key) click to toggle source
# File lib/ice_cube/builders/ical_builder.rb, line 15
def [](key)
  @hash[key] ||= []
end
to_s() click to toggle source

Build for a single rule entry

# File lib/ice_cube/builders/ical_builder.rb, line 20
def to_s
  arr = []
  if freq = @hash.delete('FREQ')
    arr << "FREQ=#{freq.join(',')}"
  end
  arr.concat(@hash.map do |key, value|
    if value.is_a?(Array)
      "#{key}=#{value.join(',')}"
    end
  end.compact)
  arr.join(';')
end