Class: Portera::Event
- Inherits:
-
Object
- Object
- Portera::Event
- Defined in:
- lib/portera/event.rb
Overview
Event model - see README for usage
Defined Under Namespace
Classes: Builder
Instance Attribute Summary collapse
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#name ⇒ Object
Returns the value of attribute name.
-
#range ⇒ Object
Returns the value of attribute range.
Instance Method Summary collapse
-
#availability(params = {}) ⇒ Object
iterate over each timeslot in range (week), gathering participant availability for each slot parameters: [
interval
]: duration of timeslots in minutes (default 15) [all
]: return all timeslots even if no participants available (default false). - #coalesced(params = {}) ⇒ Object
-
#initialize(name = nil, &proc) ⇒ Event
constructor
Define events using a block passed to the constructor, e.g.
- #participants ⇒ Object
Constructor Details
Instance Attribute Details
#duration ⇒ Object
Returns the value of attribute duration.
7 8 9 |
# File 'lib/portera/event.rb', line 7 def duration @duration end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/portera/event.rb', line 7 def name @name end |
#range ⇒ Object
Returns the value of attribute range.
7 8 9 |
# File 'lib/portera/event.rb', line 7 def range @range end |
Instance Method Details
#availability(params = {}) ⇒ Object
iterate over each timeslot in range (week), gathering participant availability for each slot parameters:
[+interval+]: duration of timeslots in minutes (default 15)
[+all+]: return all timeslots even if no participants available (default false)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/portera/event.rb', line 26 def availability(params={}) interval = params.fetch(:interval,15) keep_all = params.fetch(:all,false) iterate(interval).each_with_object(TimeslotEnum.new) do |slot, accum| avails = [] self.participants.each do |person| if person.available_for?(self, slot) avails << person end end if !avails.empty? || keep_all accum << Timeslot.new(slot, ::Set.new(avails.sort_by(&:name))) end end end |
#coalesced(params = {}) ⇒ Object
42 43 44 |
# File 'lib/portera/event.rb', line 42 def coalesced(params={}) availability(params).coalesced end |
#participants ⇒ Object
8 |
# File 'lib/portera/event.rb', line 8 def participants; @participants ||= []; end |