Class: Effective::EventTicket
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::EventTicket
- Defined in:
- app/models/effective/event_ticket.rb
Constant Summary collapse
- CATEGORIES =
['Regular', 'Member Only', 'Member or Non-Member']
Instance Method Summary collapse
- #capacity_available(except: nil) ⇒ Object
- #capacity_selectable(except: nil) ⇒ Object
- #capacity_taken(except: nil) ⇒ Object
- #member_only? ⇒ Boolean
- #member_or_non_member? ⇒ Boolean
- #non_waitlisted_event_registrants_count ⇒ Object
- #purchased_event_registrants_count ⇒ Object
- #questions ⇒ Object
- #registered_event_registrants_count ⇒ Object
- #registered_or_selected_event_registrants(except: nil) ⇒ Object
- #registered_or_selected_event_registrants_count ⇒ Object
- #regular? ⇒ Boolean
- #to_s ⇒ Object
- #waitlisted_event_registrants_count ⇒ Object
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
130 131 132 |
# File 'app/models/effective/event_ticket.rb', line 130 def member_only? category == 'Member Only' end |
#member_or_non_member? ⇒ 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_count ⇒ Object
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_count ⇒ Object
110 111 112 |
# File 'app/models/effective/event_ticket.rb', line 110 def purchased_event_registrants_count purchased_event_registrants.length end |
#questions ⇒ Object
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_count ⇒ Object
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_count ⇒ Object
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
126 127 128 |
# File 'app/models/effective/event_ticket.rb', line 126 def regular? category == 'Regular' end |
#to_s ⇒ Object
74 75 76 |
# File 'app/models/effective/event_ticket.rb', line 74 def to_s title.presence || 'New Event Ticket' end |
#waitlisted_event_registrants_count ⇒ Object
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 |