Class: Portera::Participant
- Inherits:
-
Struct
- Object
- Struct
- Portera::Participant
- 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
-
#email ⇒ Object
Returns the value of attribute email.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#available(utc_offset = nil, &sched_proc) ⇒ Object
Define availability rule passing a block, e.g.
-
#available_for?(event, slot) ⇒ Boolean
For given event range, evaluate if the given timeslot fits within any of the participant’s available times.
-
#availables ⇒ Object
List of availability rules.
-
#to_s ⇒ Object
Display participant as valid email ‘name <address>`.
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email
5 6 7 |
# File 'lib/portera/participant.rb', line 5 def email @email end |
#name ⇒ Object
Returns the value of attribute 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
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 |
#availables ⇒ Object
List of availability rules
8 |
# File 'lib/portera/participant.rb', line 8 def availables; @availables ||= []; end |
#to_s ⇒ Object
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 |