Class: Spina::Admin::Conferences::Event

Inherits:
ApplicationRecord show all
Defined in:
app/models/spina/admin/conferences/event.rb

Overview

Events during conferences.

Validators

Presence

#name, #start_time, #finish_time.

Conference date (using ConferenceDateValidator)

#start_time, #finish_time.

Translations

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#conferenceConference?

Returns directly associated conferences.

Returns:

  • (Conference, nil)

    directly associated conferences



33
# File 'app/models/spina/admin/conferences/event.rb', line 33

belongs_to :conference, -> { includes(:translations) }, inverse_of: :events, touch: true

#descriptionString?

Returns the translated description of the conference.

Returns:

  • (String, nil)

    the translated description of the conference



26
# File 'app/models/spina/admin/conferences/event.rb', line 26

translates :name, :description, :location, fallbacks: true

#locationString?

Returns the translated location of the conference.

Returns:

  • (String, nil)

    the translated location of the conference



26
# File 'app/models/spina/admin/conferences/event.rb', line 26

translates :name, :description, :location, fallbacks: true

#nameString?

Returns the translated name of the conference.

Returns:

  • (String, nil)

    the translated name of the conference



26
# File 'app/models/spina/admin/conferences/event.rb', line 26

translates :name, :description, :location, fallbacks: true

Instance Method Details

#dateDate?

Returns the start date of the event. Nil if the event has no start date and time.

Returns:

  • (Date, nil)

    the start date of the event. Nil if the event has no start date and time



40
41
42
43
44
# File 'app/models/spina/admin/conferences/event.rb', line 40

def date
  return if start_datetime.blank?

  start_datetime.to_date
end

#date=(date) ⇒ void

This method returns an undefined value.

Sets the date of the presentation.

Parameters:

  • date (Date)

    the new date



49
50
51
52
53
54
55
56
# File 'app/models/spina/admin/conferences/event.rb', line 49

def date=(date)
  if date.blank? || date.to_date.blank?
    self.start_datetime = nil
    return
  end

  self.start_datetime = date.to_date + (start_datetime.try(:seconds_since_midnight) || 0).seconds
end

#finish_timeActiveSupport::TimeWithZone?

Returns the finish time of the event. Nil if the event has no finish date and time.

Returns:

  • (ActiveSupport::TimeWithZone, nil)

    the finish time of the event. Nil if the event has no finish date and time



78
79
80
81
82
# File 'app/models/spina/admin/conferences/event.rb', line 78

def finish_time
  return if finish_datetime.blank?

  finish_datetime
end

#finish_time=(finish_time) ⇒ void

This method returns an undefined value.

Sets the finish time of the event.

Parameters:

  • finish_time (ActiveSupport::TimeWithZone)

    the new finish time



87
88
89
90
91
92
93
94
# File 'app/models/spina/admin/conferences/event.rb', line 87

def finish_time=(finish_time)
  if finish_time.blank?
    self.finish_datetime = nil
    return
  end

  self.finish_datetime = Time.parse(finish_time, date).to_datetime.in_time_zone
end

#sortedActiveRecord::Relation

Returns all events, ordered by name.

Returns:

  • (ActiveRecord::Relation)

    all events, ordered by name



29
# File 'app/models/spina/admin/conferences/event.rb', line 29

scope :sorted, -> { i18n.order :name }

#start_timeActiveSupport::TimeWithZone?

Returns the start time of the event. Nil if the event has no start date and time.

Returns:

  • (ActiveSupport::TimeWithZone, nil)

    the start time of the event. Nil if the event has no start date and time



59
60
61
62
63
# File 'app/models/spina/admin/conferences/event.rb', line 59

def start_time
  return if start_datetime.blank?

  start_datetime
end

#start_time=(start_time) ⇒ void

This method returns an undefined value.

Sets the start time of the event.

Parameters:

  • start_time (ActiveSupport::TimeWithZone)

    the new start time



68
69
70
71
72
73
74
75
# File 'app/models/spina/admin/conferences/event.rb', line 68

def start_time=(start_time)
  if start_time.blank?
    self.start_datetime = nil
    return
  end

  self.start_datetime = Time.parse(start_time, date).to_datetime.in_time_zone
end

#to_eventIcalendar::Event

Returns the event as an iCal event.

Returns:

  • (Icalendar::Event)

    the event as an iCal event



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/models/spina/admin/conferences/event.rb', line 97

def to_event # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  event = Icalendar::Event.new
  return event if invalid?

  event.dtstart = start_datetime
  event.dtend = finish_datetime
  event.location = location
  event.contact = Spina::.first.email
  event.categories = Event.model_name.human(count: 0)
  event.summary = name
  event.append_custom_property('alt_description', description.try(:html_safe))
  event.description = description.try(:gsub, %r{</?[^>]*>}, '')
  event
end

#to_icsObject

Deprecated.

Use #to_event instead



114
115
116
# File 'app/models/spina/admin/conferences/event.rb', line 114

def to_ics
  to_event
end