opening_hours_converter 1.8.0 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,18 +17,18 @@ module OpeningHoursConverter
17
17
  if interval.day_start > interval.day_end
18
18
  for day in 0..interval.day_end
19
19
  start_minute = 0
20
- end_minute = (day == interval.day_end) ? interval.end : MINUTES_MAX
20
+ end_minute = day == interval.day_end ? interval.end : MINUTES_MAX
21
21
  set_minute_array_for_interval(interval, minute_array, start_minute, end_minute, day)
22
22
  end
23
23
  for day in interval.day_start..6
24
- start_minute = (day == interval.day_start) ? interval.start : 0
24
+ start_minute = day == interval.day_start ? interval.start : 0
25
25
  end_minute = MINUTES_MAX
26
26
  set_minute_array_for_interval(interval, minute_array, start_minute, end_minute, day)
27
27
  end
28
28
  else
29
29
  for day in interval.day_start..interval.day_end
30
- start_minute = (day == interval.day_start) ? interval.start : 0
31
- end_minute = (day == interval.day_end) ? interval.end : MINUTES_MAX
30
+ start_minute = day == interval.day_start ? interval.start : 0
31
+ end_minute = day == interval.day_end ? interval.end : MINUTES_MAX
32
32
  set_minute_array_for_interval(interval, minute_array, start_minute, end_minute, day)
33
33
  end
34
34
  end
@@ -42,14 +42,12 @@ module OpeningHoursConverter
42
42
  if interval.is_off
43
43
  if start_minute && end_minute
44
44
  for minute in 0..MINUTES_MAX
45
- minute_array[day][minute] = "off"
45
+ minute_array[day][minute] = 'off'
46
46
  end
47
47
  end
48
48
  else
49
49
  if start_minute && end_minute
50
- if minute_array[day][0] == "off"
51
- minute_array[day] = Array.new(MINUTES_MAX + 1, false)
52
- end
50
+ minute_array[day] = Array.new(MINUTES_MAX + 1, false) if minute_array[day][0] == 'off'
53
51
  for minute in start_minute..end_minute
54
52
  minute_array[day][minute] = true
55
53
  end
@@ -57,7 +55,7 @@ module OpeningHoursConverter
57
55
  end
58
56
  end
59
57
 
60
- def get_intervals(clean=false)
58
+ def get_intervals(clean = false)
61
59
  if clean
62
60
  minute_array = get_as_minute_array
63
61
  intervals = []
@@ -69,12 +67,12 @@ module OpeningHoursConverter
69
67
  day.each_with_index do |minute, minute_index|
70
68
  if day_index == 0 && minute_index == 0
71
69
  if minute
72
- off = minute == "off"
70
+ off = minute == 'off'
73
71
  day_start = day_index
74
72
  minute_start = minute_index
75
73
  end
76
74
  elsif minute && day_index == DAYS_MAX && minute_index == day.length - 1
77
- off = minute == "off"
75
+ off = minute == 'off'
78
76
  if day_start >= 0
79
77
  intervals << OpeningHoursConverter::Interval.new(day_start, minute_start, day_index, minute_index, off)
80
78
  else
@@ -82,10 +80,10 @@ module OpeningHoursConverter
82
80
  end
83
81
  else
84
82
  if minute && day_start < 0
85
- off = minute == "off"
83
+ off = minute == 'off'
86
84
  day_start = day_index
87
85
  minute_start = minute_index
88
- elsif off && minute != "off"
86
+ elsif off && minute != 'off'
89
87
  intervals << OpeningHoursConverter::Interval.new(day_start, minute_start, day_index - 1, MINUTES_MAX, off)
90
88
  off = false
91
89
  day_start = minute ? day_index : -1
@@ -104,9 +102,9 @@ module OpeningHoursConverter
104
102
  end
105
103
  end
106
104
 
107
- return intervals
105
+ intervals
108
106
  else
109
- return @intervals
107
+ @intervals
110
108
  end
111
109
  end
112
110
 
@@ -114,7 +112,6 @@ module OpeningHoursConverter
114
112
  self_minutes_array = get_as_minute_array
115
113
  other_minutes_array = week.get_as_minute_array
116
114
 
117
-
118
115
  intervals = { open: [], closed: [] }
119
116
  day_start = -1
120
117
  min_start = -1
@@ -125,7 +122,7 @@ module OpeningHoursConverter
125
122
  off = false
126
123
  intervals_length = intervals[:open].length
127
124
  while m <= MINUTES_MAX
128
- off = self_minutes_array[d][m] == "off"
125
+ off = self_minutes_array[d][m] == 'off'
129
126
  break if off
130
127
  # Copy entire day
131
128
  if diff_day
@@ -160,11 +157,11 @@ module OpeningHoursConverter
160
157
  m += 1
161
158
  # check diff
162
159
  else
163
- if !self_minutes_array[d][m]
164
- diff_day = other_minutes_array[d][m] != "off" && other_minutes_array[d][m]
165
- else
166
- diff_day = other_minutes_array[d][m] == "off" || !other_minutes_array[d][m]
167
- end
160
+ diff_day = if !self_minutes_array[d][m]
161
+ other_minutes_array[d][m] != 'off' && other_minutes_array[d][m]
162
+ else
163
+ other_minutes_array[d][m] == 'off' || !other_minutes_array[d][m]
164
+ end
168
165
 
169
166
  if diff_day
170
167
  m = 0
@@ -174,12 +171,12 @@ module OpeningHoursConverter
174
171
  end
175
172
  end
176
173
  if !diff_day && day_start > -1 && !off
177
- intervals[:open] << OpeningHoursConverter::Interval.new(day_start, min_start, d-1, MINUTES_MAX, off)
174
+ intervals[:open] << OpeningHoursConverter::Interval.new(day_start, min_start, d - 1, MINUTES_MAX, off)
178
175
  day_start = -1
179
176
  min_start = -1
180
177
  end
181
178
  if diff_day && day_start == -1 && intervals_length == intervals[:open].length || off
182
- if intervals[:closed].length > 0 && intervals[:closed][intervals[:closed].length - 1].day_end == d - 1
179
+ if !intervals[:closed].empty? && intervals[:closed][intervals[:closed].length - 1].day_end == d - 1
183
180
  intervals[:closed][-1] = OpeningHoursConverter::Interval.new(intervals[:closed].last.day_start, 0, d, MINUTES_MAX, off)
184
181
  else
185
182
  intervals[:closed] << OpeningHoursConverter::Interval.new(d, 0, d, MINUTES_MAX, off)
@@ -187,12 +184,12 @@ module OpeningHoursConverter
187
184
  end
188
185
  end
189
186
 
190
- return intervals
187
+ intervals
191
188
  end
192
189
 
193
190
  def add_interval(interval)
194
191
  @intervals << interval
195
- return @intervals.length - 1
192
+ @intervals.length - 1
196
193
  end
197
194
 
198
195
  def edit_interval(id, interval)
@@ -205,23 +202,20 @@ module OpeningHoursConverter
205
202
 
206
203
  def remove_intervals_during_day(day)
207
204
  @intervals.each_with_index do |interval, i|
208
- unless interval.nil?
209
- if interval.day_start <= day && interval.day_end >= day
210
- day_diff = interval.day_end - interval.day_start
211
-
212
- if day_diff > 1 || day_diff == 0 || interval.day_start == day || interval.start <= interval.end
213
- if interval.day_end - interval.day_start >= 1 && interval.start <= interval.end
214
- if interval.day_start < day
215
- add_interval(OpeningHoursConverter::Interval.new(interval.day_start, interval.start, day - 1, 24*60, interval.is_off))
216
- end
217
- if interval.day_end > day
218
- add_interval(OpeningHoursConverter::Interval.new(day + 1, 0, interval.day_end, interval.end, interval.is_off))
219
- end
220
- end
221
- remove_interval(i)
222
- end
205
+ next if interval.nil?
206
+ next unless interval.day_start <= day && interval.day_end >= day
207
+ day_diff = interval.day_end - interval.day_start
208
+
209
+ next unless day_diff > 1 || day_diff == 0 || interval.day_start == day || interval.start <= interval.end
210
+ if interval.day_end - interval.day_start >= 1 && interval.start <= interval.end
211
+ if interval.day_start < day
212
+ add_interval(OpeningHoursConverter::Interval.new(interval.day_start, interval.start, day - 1, 24 * 60, interval.is_off))
213
+ end
214
+ if interval.day_end > day
215
+ add_interval(OpeningHoursConverter::Interval.new(day + 1, 0, interval.day_end, interval.end, interval.is_off))
223
216
  end
224
217
  end
218
+ remove_interval(i)
225
219
  end
226
220
  end
227
221
 
@@ -233,9 +227,7 @@ module OpeningHoursConverter
233
227
  @intervals = []
234
228
 
235
229
  intervals.each do |interval|
236
- if !interval.nil? && !interval.is_off
237
- @intervals << interval.dup
238
- end
230
+ @intervals << interval.dup if !interval.nil? && !interval.is_off
239
231
  end
240
232
  end
241
233