Class: Spina::Admin::Conferences::PresentationType

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/spina/admin/conferences/presentation_type.rb

Overview

Presentation type records.

Validators

Presence

#name, #minutes. #duration.

Translations

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#conferenceConference?

Returns directly associated conference.

Returns:

  • (Conference, nil)

    directly associated conference



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

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

#durationActiveSupport::Duration?

Returns the duration of dependent presentations.

Returns:

  • (ActiveSupport::Duration, nil)

    the duration of dependent presentations



25
# File 'app/models/spina/admin/conferences/presentation_type.rb', line 25

attribute :duration, :interval

#nameString?

Returns the name of the presentation type.

Returns:

  • (String, nil)

    the name of the presentation type



18
# File 'app/models/spina/admin/conferences/presentation_type.rb', line 18

translates :name, fallbacks: true

#presentationsActiveRecord::Relation

Returns Presentations associated with #sessions.

Returns:

  • (ActiveRecord::Relation)

    Presentations associated with #sessions

See Also:



39
# File 'app/models/spina/admin/conferences/presentation_type.rb', line 39

has_many :presentations, -> { distinct.includes(:translations) }, through: :sessions

#sessionsActiveRecord::Relation

Note:

A presentation type cannot be destroyed if it has dependent sessions.

Returns directly associated sessions.

Returns:

  • (ActiveRecord::Relation)

    directly associated sessions

See Also:



34
# File 'app/models/spina/admin/conferences/presentation_type.rb', line 34

has_many :sessions, -> { includes(:translations) }, inverse_of: :presentation_type, dependent: :restrict_with_error

Instance Method Details

#minutesInteger?

Returns duration in minutes. Nil if the conference has no duration.

Returns:

  • (Integer, nil)

    duration in minutes. Nil if the conference has no duration



45
46
47
48
49
# File 'app/models/spina/admin/conferences/presentation_type.rb', line 45

def minutes
  return if duration.blank?

  duration.to_i / ActiveSupport::Duration::PARTS_IN_SECONDS[:minutes]
end

#minutes=(minutes) ⇒ void

This method returns an undefined value.

Sets the duration of the conference.

Parameters:

  • minutes (#to_i)

    the new duration in minutes



54
55
56
# File 'app/models/spina/admin/conferences/presentation_type.rb', line 54

def minutes=(minutes)
  self.duration = minutes.to_i.minutes
end

#sortedActiveRecord::Relation

Returns all presentation types, ordered by name.

Returns:

  • (ActiveRecord::Relation)

    all presentation types, ordered by name



21
# File 'app/models/spina/admin/conferences/presentation_type.rb', line 21

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