Class: Spina::Admin::Conferences::TimePart

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

Overview

Time parts.

Instance Method Summary collapse

Instance Method Details

#dateDate?

Returns the date of the time part. Nil if the time part has no date and time.

Returns:

  • (Date, nil)

    the date of the time part. Nil if the time part has no date and time



14
15
16
17
18
# File 'app/models/spina/admin/conferences/time_part.rb', line 14

def date
  return if content.blank?

  content.to_date
end

#date=(date) ⇒ void

This method returns an undefined value.

Sets the date of the time part.

Parameters:

  • date (Date)

    the new date



23
24
25
26
27
28
29
30
# File 'app/models/spina/admin/conferences/time_part.rb', line 23

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

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

#timeActiveSupport::TimeWithZone?

Returns the time of the time part. Nil if the time part has no date and time.

Returns:

  • (ActiveSupport::TimeWithZone, nil)

    the time of the time part. Nil if the time part has no date and time



33
34
35
36
37
# File 'app/models/spina/admin/conferences/time_part.rb', line 33

def time
  return if content.blank?

  content
end

#time=(time) ⇒ void

This method returns an undefined value.

Sets the start time of the time part.

Parameters:

  • time (ActiveSupport::TimeWithZone)

    the new time



42
43
44
45
46
47
48
49
# File 'app/models/spina/admin/conferences/time_part.rb', line 42

def time=(time)
  if time.blank?
    self.content = nil
    return
  end

  self.content = Time.parse(time, date).to_datetime.in_time_zone
end