Module: RST::Calendar::Eventable

Included in:
CalendarEvent
Defined in:
lib/modules/calendar/eventable.rb

Overview

Inject Eventable to any Class to make it event-able in a Calendar You have to define a method :event_headline for the class in order to list the event in a Calendar.

Examples:


class Birthday < Struct.new(:name,:dob)
  include Eventable
  def initialize(*args)
    super
    schedule!(dob)
  end

  protected
  def event_headline
    "It's #{name}'s Birthday"
  end
end

See Also:

Instance Method Summary collapse

Instance Method Details

#event_dateDate

Returns the date when the event is scheduled.

Returns:

  • (Date)

    the date when the event is scheduled



27
28
29
# File 'lib/modules/calendar/eventable.rb', line 27

def event_date
  @event_date
end

#event_headlineString

This method is abstract.
  • overwrite in descendants

used in calendar-output as a short entry

Returns:



46
47
48
# File 'lib/modules/calendar/eventable.rb', line 46

def event_headline
  self.inspect
end

#schedule!(date) ⇒ Eventable

Returns - self.

Parameters:

  • date (Date|String)

    schedule this object for the given date

Returns:



38
39
40
41
# File 'lib/modules/calendar/eventable.rb', line 38

def schedule!(date)
  @event_date = date.is_a?(Date) ? date : Date.parse(date)
  self
end

#scheduled?Boolean

Returns true if the object is scheduled (has an event_date).

Returns:

  • (Boolean)

    true if the object is scheduled (has an event_date)



32
33
34
# File 'lib/modules/calendar/eventable.rb', line 32

def scheduled?
  !event_date.nil?
end