forked from sixthkind/loopdo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceProvider.rb
148 lines (128 loc) · 3.87 KB
/
serviceProvider.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
class ServiceProvider
attr_reader :name, :phoneNum, :services, :availability, :appointments, :serviceAdd
def initialize(name, phoneNum, services, availability, appointments) (
@name = name
@phoneNum = phoneNum
@services = services
@availability = availability
@appointments = appointments
)
end
def serviceRemove(service_name) (
for service in @services do
if service.name == service_name
@services.delete(service)
end
end
)
end
def printServices()
puts "#{Magenta}#{@name}#{Reset}'s Services:"
@services.each do |s|
s.printDetails
end
end
def scheduleView()
puts
puts "#{Magenta}#{@name}#{Reset}'s Appointments:"
@appointments.each do |a|
a.printDetails
end
puts
end
def availabilityView()
puts
puts "#{Magenta}#{@name}#{Reset}'s Availability:"
@availability.each do |a|
puts "#{BgCyan}AVAILABILITY#{Reset}"
a.printDetails
end
puts
end
def containsService(name) (
for service in @services do
if service.name == name
return service
end
end
return false
)
end
def serviceAdd(service) (
@services.push(service)
)
end
def is_available(service, timeblock, isWeekly)
#add check to make sure timeblock is in the future
is_future_date = (timeblock.startTime >= DateTime.now)
#check if provider offers service
service_offered = containsService(service.name)
# puts('past service_offered')
#check provider's availability
# availability_blocks = @availability[timeblock.dayOfWeek]
# puts('past availability_blocks')
#IDK what is wrong with this but causes program to crash, commented out for now
# provider_available = false
# for block in availability_blocks do
# if block.contains(timeblock)
# provider_available = true
# end
# end
#
provider_available = true
#check for overlap with provider's appointments
no_overlap_with_appointments = true
puts('-----------------')
@appointments.each do |appointment|
#check for overlap if either appointment is weekly
if appointment.timeblock.isWeekly || isWeekly
if appointment.timeblock.dayOfWeek == timeblock.dayOfWeek
if appointment.timeblock.overlaps_time(timeblock)
no_overlap_with_appointments = false
end
end
end
#check for overlap if dates are the same
if appointment.timeblock.overlaps(timeblock)
no_overlap_with_appointments = false
end
end
availability_contains = true
@availability.each do |av|
#check if appointment is contained within availability if availability is weekly
if av.isWeekly || isWeekly
if av.dayOfWeek == timeblock.dayOfWeek
if !av.contains_time(timeblock)
availability_contains = false
end
end
else
#check if appointment is contained within availability on same date
if av.month == timeblock.month && av.day == timeblock.day && av.year == timeblock.year
if !av.contains(timeblock)
availability_contains = false
end
end
end
end
return is_future_date && service_offered && provider_available &&
no_overlap_with_appointments && availability_contains
end
def add_appointment(service, timeblock, client)
#add appointment to provider's schedule
if is_available(service, timeblock, timeblock.isWeekly)
appointment = Appointment.new(timeblock, service, client, self)
@appointments << appointment
successPrint()
return true
else
puts "#{Red}The service provider you requested is not available at this time."
puts "Please choose a different date/time.#{Reset}"
return false
end
end
def add_availability(timeblock)
#need to add a check here
@availability << timeblock
end
end