Class: Effective::EventTicket

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

Constant Summary collapse

CATEGORIES =
['Regular', 'Member Only', 'Member or Non-Member']

Instance Method Summary collapse

Instance Method Details

#capacity_available(except: nil) ⇒ Object



85
86
87
88
# File 'app/models/effective/event_ticket.rb', line 85

def capacity_available(except: nil)
  return nil if capacity.blank?
  [(capacity - capacity_taken(except: except)), 0].max
end

#capacity_selectable(except: nil) ⇒ Object



78
79
80
81
82
83
# File 'app/models/effective/event_ticket.rb', line 78

def capacity_selectable(except: nil)
  return nil if capacity.blank?
  return nil if waitlist?

  capacity_available(except: except)
end

#capacity_taken(except: nil) ⇒ Object



90
91
92
# File 'app/models/effective/event_ticket.rb', line 90

def capacity_taken(except: nil)
  registered_or_selected_event_registrants(except: except).reject(&:waitlisted?).length
end

#member_only?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'app/models/effective/event_ticket.rb', line 130

def member_only?
  category == 'Member Only'
end

#member_or_non_member?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'app/models/effective/event_ticket.rb', line 134

def member_or_non_member?
  category == 'Member or Non-Member'
end

#non_waitlisted_event_registrants_countObject



114
115
116
# File 'app/models/effective/event_ticket.rb', line 114

def non_waitlisted_event_registrants_count
  registered_event_registrants.where(waitlisted: false).or(registered_event_registrants.where(waitlisted: true, promoted: true))
end

#purchased_event_registrants_countObject



110
111
112
# File 'app/models/effective/event_ticket.rb', line 110

def purchased_event_registrants_count
  purchased_event_registrants.length
end

#questionsObject



122
123
124
# File 'app/models/effective/event_ticket.rb', line 122

def questions
  [question1.presence, question2.presence, question3.presence].compact
end

#registered_event_registrants_countObject



106
107
108
# File 'app/models/effective/event_ticket.rb', line 106

def registered_event_registrants_count
  registered_event_registrants.length
end

#registered_or_selected_event_registrants(except: nil) ⇒ Object



94
95
96
97
98
99
100
# File 'app/models/effective/event_ticket.rb', line 94

def registered_or_selected_event_registrants(except: nil)
  raise('expected except to be an EventRegistration') if except && !except.class.try(:effective_events_event_registration?)

  event_registrants.select do |er| 
    (er.registered? || er.selected_not_expired?) && (except.blank? || er.event_registration_id != except.id)
  end
end

#registered_or_selected_event_registrants_countObject



102
103
104
# File 'app/models/effective/event_ticket.rb', line 102

def registered_or_selected_event_registrants_count
  registered_or_selected_event_registrants.count
end

#regular?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'app/models/effective/event_ticket.rb', line 126

def regular?
  category == 'Regular'
end

#to_sObject



74
75
76
# File 'app/models/effective/event_ticket.rb', line 74

def to_s
  title.presence || 'New Event Ticket'
end

#waitlisted_event_registrants_countObject



118
119
120
# File 'app/models/effective/event_ticket.rb', line 118

def waitlisted_event_registrants_count
  registered_event_registrants.where(waitlisted: true, promoted: false).length
end