Class: CalInvite::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/cal_invite/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Event

Initializes a new Event instance with the given attributes.

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes to initialize the event with

Options Hash (attributes):

  • :title (String)

    The event title

  • :start_time (Time)

    The event start time

  • :end_time (Time)

    The event end time

  • :description (String)

    The event description

  • :location (String)

    The event location

  • :url (String)

    The event URL

  • :attendees (Array<String>)

    The event attendees

  • :timezone (String) — default: 'UTC'

    The event timezone

  • :show_attendees (Boolean) — default: false

    Whether to show attendees

  • :notes (String)

    Additional notes

  • :multi_day_sessions (Array<Hash>)

    Multi-day session details

  • :all_day (Boolean) — default: false

    Whether it’s an all-day event

Raises:

  • (ArgumentError)

    If required attributes are missing



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cal_invite/event.rb', line 52

def initialize(attributes = {})
  @show_attendees = attributes.delete(:show_attendees) || false
  @timezone = attributes.delete(:timezone) || 'UTC'
  @multi_day_sessions = attributes.delete(:multi_day_sessions) || []
  @all_day = attributes.delete(:all_day) || false

  attributes.each do |key, value|
    send("#{key}=", value) if respond_to?("#{key}=")
  end

  validate!
end

Instance Attribute Details

#all_dayObject

Returns the value of attribute all_day.



22
23
24
# File 'lib/cal_invite/event.rb', line 22

def all_day
  @all_day
end

#attendeesObject

Returns the value of attribute attendees.



22
23
24
# File 'lib/cal_invite/event.rb', line 22

def attendees
  @attendees
end

#descriptionObject

Returns the value of attribute description.



22
23
24
# File 'lib/cal_invite/event.rb', line 22

def description
  @description
end

#end_timeObject

Returns the value of attribute end_time.



22
23
24
# File 'lib/cal_invite/event.rb', line 22

def end_time
  @end_time
end

#locationObject

Returns the value of attribute location.



22
23
24
# File 'lib/cal_invite/event.rb', line 22

def location
  @location
end

#multi_day_sessionsObject

Returns the value of attribute multi_day_sessions.



22
23
24
# File 'lib/cal_invite/event.rb', line 22

def multi_day_sessions
  @multi_day_sessions
end

#notesObject

Returns the value of attribute notes.



22
23
24
# File 'lib/cal_invite/event.rb', line 22

def notes
  @notes
end

#show_attendeesObject

Returns the value of attribute show_attendees.



22
23
24
# File 'lib/cal_invite/event.rb', line 22

def show_attendees
  @show_attendees
end

#start_timeObject

Returns the value of attribute start_time.



22
23
24
# File 'lib/cal_invite/event.rb', line 22

def start_time
  @start_time
end

#timezoneObject

Returns the value of attribute timezone.



22
23
24
# File 'lib/cal_invite/event.rb', line 22

def timezone
  @timezone
end

#titleObject

Returns the value of attribute title.



22
23
24
# File 'lib/cal_invite/event.rb', line 22

def title
  @title
end

#urlObject

Returns the value of attribute url.



22
23
24
# File 'lib/cal_invite/event.rb', line 22

def url
  @url
end

Instance Method Details

#generate_calendar_url(provider) ⇒ String

Generates a calendar URL for the specified provider.

Examples:

Generate a Google Calendar URL

event.generate_calendar_url(:google)

Generate an Outlook Calendar URL

event.generate_calendar_url(:outlook)

Parameters:

  • provider (Symbol)

    The calendar provider to generate the URL for

Returns:

  • (String)

    The generated calendar URL

Raises:

  • (ArgumentError)

    If required event attributes are missing



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/cal_invite/event.rb', line 76

def generate_calendar_url(provider)
  validate!

  if caching_enabled?
    cache_key = cache_key_for(provider)
    cached_url = fetch_from_cache(cache_key)
    return cached_url if cached_url
  end

  # Generate the URL
  provider_class = CalInvite::Providers.const_get(capitalize_provider(provider.to_s))
  generator = provider_class.new(self)
  url = generator.generate

  # Cache the result if caching is enabled
  write_to_cache(cache_key, url) if caching_enabled?

  url
end

#update_attributes(new_attributes) ⇒ void

This method returns an undefined value.

Updates the event attributes with new values.

Examples:

Update event title and time

event.update_attributes(
  title: "Updated Meeting",
  start_time: Time.now + 3600
)

Parameters:

  • new_attributes (Hash)

    The new attributes to update

Raises:

  • (ArgumentError)

    If the updated attributes make the event invalid



107
108
109
110
111
112
113
114
# File 'lib/cal_invite/event.rb', line 107

def update_attributes(new_attributes)
  new_attributes.each do |key, value|
    send("#{key}=", value) if respond_to?("#{key}=")
  end

  invalidate_cache if caching_enabled?
  validate!
end