class Mhc::Occurrence

Attributes

event[R]

Public Class Methods

new(event, date_range) click to toggle source
# File lib/mhc/occurrence.rb, line 26
def initialize(event, date_range)
  @event = event

  if date_range.respond_to?(:first)
    @start_date = date_range.first
    @end_date   = date_range.last
  else
    @start_date = date_range
    @end_date   = date_range
  end
end

Public Instance Methods

<=>(o) click to toggle source
# File lib/mhc/occurrence.rb, line 108
def <=>(o)
  if o.respond_to?(:dtstart)
    return self.dtstart <=> o.dtstart
  else
    return self.dtstart <=> o
  end
end
date() click to toggle source
# File lib/mhc/occurrence.rb, line 38
def date
  if @start_date.respond_to?(:hour)
    Mhc::PropertyValue::Date.new(@start_date.year, @start_date.month, @start_date.day)
  else
    @start_date
  end
end
days() click to toggle source
# File lib/mhc/occurrence.rb, line 88
def days
  @end_date - @start_date + 1
end
dtend() click to toggle source
# File lib/mhc/occurrence.rb, line 68
def dtend
  if allday?
    @end_date + 1
  else
    if @end_date.respond_to?(:hour)
      @end_date
    else
      @event.time_range.last.to_datetime(@end_date)
    end
  end
end
dtstart() click to toggle source
# File lib/mhc/occurrence.rb, line 56
def dtstart
  if allday?
    @start_date
  else
    if @start_date.respond_to?(:hour)
      @start_date
    else
      @event.time_range.first.to_datetime(@start_date)
    end
  end
end
first() click to toggle source
# File lib/mhc/occurrence.rb, line 80
def first
  @start_date
end
last() click to toggle source
# File lib/mhc/occurrence.rb, line 84
def last
  @end_date
end
oneday?() click to toggle source
# File lib/mhc/occurrence.rb, line 92
def oneday?
  @start_date == @end_date
end
time_range() click to toggle source

FIXME: TimeRange class should be implemented

# File lib/mhc/occurrence.rb, line 47
def time_range
  range = Mhc::PropertyValue::Range.new(Mhc::PropertyValue::Time)
  if dtstart.respond_to?(:hour)
    range.parse("#{dtstart.hour}:#{dtstart.min}-#{dtend.hour}:#{dtend.min}")
  else
    return range # allday
  end
end
to_mhc_string() click to toggle source
# File lib/mhc/occurrence.rb, line 96
def to_mhc_string
  if allday?
    return "#{dtstart.to_mhc_string}" if oneday?
    return "#{@start_date.to_mhc_string}-#{@end_date.to_mhc_string}"
  else
    time = dtstart.strftime("%Y%m%d %H:%m-") + ((@start_date.to_date == @end_date.to_date) ? dtend.strftime("%H:%m") : dtend.strftime("%Y%m%dT%H:%m"))
    return time + " " + subject.to_mhc_string
  end
end
Also aliased as: to_s
to_s()
Alias for: to_mhc_string