Class: Portera::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/portera/event.rb

Overview

Event model - see README for usage

Defined Under Namespace

Classes: Builder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, &proc) ⇒ Event

Define events using a block passed to the constructor, e.g.

Event.new do
  duration 60
  week_of  Date.civil(2012,2,13)
end


16
17
18
19
# File 'lib/portera/event.rb', line 16

def initialize(name=nil,&proc)
  self.name = name
  Builder.new(self).instance_eval(&proc)
end

Instance Attribute Details

#durationObject

Returns the value of attribute duration.



7
8
9
# File 'lib/portera/event.rb', line 7

def duration
  @duration
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/portera/event.rb', line 7

def name
  @name
end

#rangeObject

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

#participantsObject



8
# File 'lib/portera/event.rb', line 8

def participants; @participants ||= []; end