Class: SocialFramework::ScheduleHelper::Graph

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/social_framework/schedule_helper.rb

Overview

Represent the schedule on a Graph, with Vertices and Edges

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_duration = SocialFramework.max_duration_to_schedule_graph) ⇒ Graph

Init the slots and users in Array

Params:
max_duration

ActiveSupport::Duration used to define max finish day to build graph

Returns Graph’s Instance



14
15
16
17
18
19
# File 'app/helpers/social_framework/schedule_helper.rb', line 14

def initialize max_duration = SocialFramework.max_duration_to_schedule_graph
  @slots = Array.new
  @users = Array.new
  @fixed_users = Array.new
  @max_duration = max_duration
end

Instance Attribute Details

#slotsObject

Returns the value of attribute slots.



8
9
10
# File 'app/helpers/social_framework/schedule_helper.rb', line 8

def slots
  @slots
end

Instance Method Details

#build(users, start_day, finish_day, start_hour = Time.parse("00:00"), finish_hour = Time.parse("23:59"), slots_size = SocialFramework.slots_size) ⇒ Object

Init the slots and users in Array

Params:
users

Array users to check disponibility

start_day

Date start day to get slots

finish_day

Date finish day to get slots

start_hour

Time start hour at each day to get slots

finish_hour

Time finish hour at each day to get slots

slots_size

Integer slots size duration

Returns The Graph mounted



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/social_framework/schedule_helper.rb', line 30

def build(users, start_day, finish_day, start_hour = Time.parse("00:00"), finish_hour = Time.parse("23:59"), slots_size = SocialFramework.slots_size)
  return unless finish_day_ok? start_day, finish_day

  @slots_size = slots_size
  start_time = start_day.to_datetime + start_hour.seconds_since_midnight.seconds
  finish_time = finish_day.to_datetime + finish_hour.seconds_since_midnight.seconds

  build_users(users)
  build_slots(start_time, finish_time, start_hour, finish_hour)

  unless @fixed_users.empty?
    build_edges(@fixed_users, start_time, finish_time)

    @slots.select! { |slot| slot.edges.count == @fixed_users.count }
  end

  build_edges(@users, start_time, finish_time)

  @slots.sort_by! { |slot| -slot.attributes[:gained_weight] }
end