Class: Portera::Participant

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

Overview

Participant model - for use with event(s). See README for usage.

Defined Under Namespace

Classes: Availability, Builder

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#emailObject

Returns the value of attribute email

Returns:

  • (Object)

    the current value of email



5
6
7
# File 'lib/portera/participant.rb', line 5

def email
  @email
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



5
6
7
# File 'lib/portera/participant.rb', line 5

def name
  @name
end

Instance Method Details

#available(utc_offset = nil, &sched_proc) ⇒ Object

Define availability rule passing a block, e.g.

participant.available('+09:00') do
  weekdays :from => '11:00am', :to => '3:00pm'
  on [0,6] :from => '5:00pm', :to => '6:30pm'
end


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

def available(utc_offset=nil, &sched_proc)
  Builder.new(self.availables,utc_offset).instance_eval(&sched_proc)
  self
end

#available_for?(event, slot) ⇒ Boolean

For given event range, evaluate if the given timeslot fits within any of the participant’s available times

Note that range-availability arrays are cached here per event Possibly caching should be moved down into Tempr, e.g.

avail.for_range(event.range).all   #=> caches within Tempr::SubRangeIterator

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/portera/participant.rb', line 27

def available_for?(event, slot)
  availables.any? do |avail|
    cache[event.range] ||= avail.for_range(event.range).to_a
    cache[event.range].any? {|free| free.subsume?(slot)}
  end
end

#availablesObject

List of availability rules



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

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

#to_sObject

Display participant as valid email ‘name <address>`



35
36
37
38
39
# File 'lib/portera/participant.rb', line 35

def to_s
  [self.name  ? "#{self.name}"    : nil,
   self.email ? "<#{self.email}>" : nil
  ].compact.join(" ")
end