Class: Effective::MentorshipCycle

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/mentorship_cycle.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.effective_mentorships_cycle?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/models/effective/mentorship_cycle.rb', line 58

def self.effective_mentorships_cycle?
  true
end

.latest_cycleObject



62
63
64
# File 'app/models/effective/mentorship_cycle.rb', line 62

def self.latest_cycle
  order(start_at: :desc).first
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/models/effective/mentorship_cycle.rb', line 87

def available?
  started? && !ended?
end

#available_dateObject



111
112
113
114
115
116
117
# File 'app/models/effective/mentorship_cycle.rb', line 111

def available_date
  if start_at && end_at
    "#{start_at.strftime('%F')} to #{end_at.strftime('%F')}"
  elsif start_at
    "#{start_at.strftime('%F')}"
  end
end

#duplicateObject

Returns a duplicated event object, or throws an exception



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/effective/mentorship_cycle.rb', line 71

def duplicate
  MentorshipCycle.new(attributes.except('id', 'updated_at', 'created_at', 'token')).tap do |resource|
    # Duplicate mentorship cycle
    resource.title = title + ' (Copy)'

    # Duplicate all date fields and move them ahead 1-year
    resource.start_at = start_at&.advance(years: 1)
    resource.end_at = end_at&.advance(years: 1)
    resource.registration_start_at = registration_start_at&.advance(years: 1)
    resource.registration_end_at = registration_end_at&.advance(years: 1)

    # Duplicate all rich texts
    rich_texts.each { |rt| resource.send("rich_text_#{rt.name}=", rt.body) }
  end
end

#ended?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/models/effective/mentorship_cycle.rb', line 95

def ended?
  end_at.present? && end_at < Time.zone.now
end

#registrable?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'app/models/effective/mentorship_cycle.rb', line 99

def registrable?
  registration_started? && !registration_ended?
end

#registrable_dateObject



119
120
121
122
123
124
125
# File 'app/models/effective/mentorship_cycle.rb', line 119

def registrable_date
  if registration_start_at && registration_end_at
    "#{registration_start_at.strftime('%F')} to #{registration_end_at.strftime('%F')}"
  elsif registration_start_at
    "#{registration_start_at.strftime('%F')}"
  end
end

#registration_ended?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/models/effective/mentorship_cycle.rb', line 107

def registration_ended?
  registration_end_at.present? && registration_end_at < Time.zone.now
end

#registration_started?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'app/models/effective/mentorship_cycle.rb', line 103

def registration_started?
  registration_start_at.present? && Time.zone.now >= registration_start_at
end

#started?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'app/models/effective/mentorship_cycle.rb', line 91

def started?
  start_at.present? && Time.zone.now >= start_at
end

#to_sObject



66
67
68
# File 'app/models/effective/mentorship_cycle.rb', line 66

def to_s
  title.presence || model_name.human
end