Class: Event

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

Overview

This model manage the events for analisys and visits

Relations

Validations

After Save

  • #add_meetings

Default scope

ordered by date_on asc

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

#div

Instance Attribute Details

#bodyString

Returns optional description.

Returns:

  • (String)

    optional description



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

#cityString

Returns is the event’s reference city.

Returns:

  • (String)

    is the event’s reference city



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

#created_atDatetime

Returns date when the record was created.

Returns:

  • (Datetime)

    date when the record was created



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

#date_onDate

Returns event’s date.

Returns:

  • (Date)

    event’s date



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

#genderString

is an enum with the possible type of event. Is mandatory.

Returns:

  • (String)

    ‘analisys’ if value is 0

  • (String)

    ‘visit’ if value is 1



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

#idsArray

Is an attr_accessor, Is the list of related User, is required for create o update related meeting

Returns:

  • (Array)

    list of User



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

#max_userInteger

is mandatory, default is 10

Returns:

  • (Integer)

    is the max number of User for the event



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

#start_atDatetime

Is an attr_accessor, is required, is used for make related Meeting

Returns:

  • (Datetime)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

#stateString

Is an attr_accessor, is the new state for related Meeting

Returns:

  • (String)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

#updated_atDatetime

Returns date when the record was updated.

Returns:

  • (Datetime)

    date when the record was updated



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

#userObject

Is an attr_accessor, Is a reference user

Returns:

  • (Object)

    User instance



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

Class Method Details

.between(start_on: Time.zone.today-1.month, stop_on: Time.zone.today) ⇒ Array

Returns of Event with #date_on from :start_on and :stop_on.

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

Instance Method Details

#auditsArray

Returns of related Audit.

Returns:

  • (Array)

    of related Audit



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

#categories(user) ⇒ String

Returns All Event.categorycategory.title planed for this event for a User.

Returns:

  • (String)

    All Event.categorycategory.title planed for this event for a User



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

def categories(user)
  meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
end

#future(start_on: Time.zone.today-1.month, stop_on: Time.zone.today) ⇒ Array

Returns of Event with #date_on greater than :date.

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

#meetingsArray

Returns of related Meeting.

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end

#start_onString, Null

Returns:



82
83
84
# File 'app/models/event.rb', line 82

def start_on
  start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
end

#status(user) ⇒ Symbol

Returns:

  • (Symbol)

    Event.auditaudit.status of first Audit

  • (Symbol)

    :not_assigned if no any Audit is present



88
89
90
# File 'app/models/event.rb', line 88

def status(user)
  meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
end

#time(user) ⇒ String

Returns strftime of Event.meetingmeeting.start_at from first related Meeting.

Returns:

  • (String)

    strftime of Event.meetingmeeting.start_at from first related Meeting



93
94
95
96
# File 'app/models/event.rb', line 93

def time(user)
  meeting = meetings.find_by(audit_id: user.audit_ids)
  meeting.start_at.strftime('%H:%M')
end

#update_status!True, False

Update the status of the Meeting related to an User

Returns:

  • (True)

    if all Meeting are updated

  • (False)

    if Meeting isn’t updated



106
107
108
109
110
111
112
113
114
# File 'app/models/event.rb', line 106

def update_status!
  new_status = case status(user)
               when 'proposed' then 2
               when 'waiting' then 3
               when 'confirmed' then 0
               when 'blocked' then 1
               end
  user_meetings.find_each { |m| m.update(status: new_status) }
end

#usersArray

Returns of related User.

Returns:

  • (Array)

    of related User



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/event.rb', line 61

class Event < ApplicationRecord
  has_many :meetings, dependent: :destroy
  has_many :audits, through: :meetings
  has_many :users, through: :audits
  has_many :user_meetings, ->(e) { where(audit_id: e.user.audit_ids) }, class_name: 'Meeting', inverse_of: :event
  attr_accessor :start_at, :state, :ids, :user

  validates :date_on, presence: true, uniqueness: { scope: %i[city gender] }
  validates :start_at, presence: true

  after_save :add_meetings

  enum gender: { analisys: 0, visit: 1 }

  default_scope -> { order('date_on asc') }
  scope :between, ->(start_on: Time.zone.today - 1.month, stop_on: Time.zone.today) { where('date_on >= :start_on and date_on <= :stop_on', start_on: start_on, stop_on: stop_on) }
  scope :future, ->(date: Time.zone.today) { where('date_on >= ?', date) }
  scope :confirmed, -> { joins(:meetings).where(meetings: {status: :confirmed}) }

  # @return [String] {start_at} to string if present
  # @return [Null] if {start_at} is null
  def start_on
    start_at.to_datetime.strftime('%d/%m/%Y %H:%M:%S') if start_at.present?
  end

  # @return [Symbol] {audit.status} of first {Audit}
  # @return [Symbol] :not_assigned if no any {Audit} is present
  def status(user)
    meetings.find_by(audit_id: user.audit_ids).try(:status) || :not_assigned
  end

  # @return [String] strftime of {meeting.start_at} from first related {Meeting}
  def time(user)
    meeting = meetings.find_by(audit_id: user.audit_ids)
    meeting.start_at.strftime('%H:%M')
  end

  # @return [String] All {category.title} planed for this event for a {User}
  def categories(user)
    meetings.where(audit_id: user.audit_ids).map { |m| m.category.title }.join(', ')
  end

  # Update the status of the {Meeting} related to an User
  # @return [True] if all {Meeting} are updated
  # @return [False] if {Meeting} isn't updated
  def update_status!
    new_status = case status(user)
                 when 'proposed' then 2
                 when 'waiting' then 3
                 when 'confirmed' then 0
                 when 'blocked' then 1
                 end
    user_meetings.find_each { |m| m.update(status: new_status) }
  end

  private

  # Add or update all {Meeting} from {ids}
  def add_meetings
    audits = ids.compact
    audits.each { |audit| meetings.find_or_initialize_by(audit_id: audit).update(start_at: start_at, status: state) }
  end
end