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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50b769d524ea032bea248de2b6dded3bfd944f3f3402f4213ef160075f4c68e6
4
- data.tar.gz: 64ca508b6a8d07c9354e22c3371a1a51d77452eba94d2d5826f133ce26591e37
3
+ metadata.gz: 8182729b4890b6c79b8173b5ed0722da103a4f82820ff62119d63f2d0ca2de72
4
+ data.tar.gz: bbbab689b9eddebb5dd17e715a15c940dd62cd0fa58b06b860c1234544c2bdf7
5
5
  SHA512:
6
- metadata.gz: 2a86e27cd5699f95e1bd25559b22df74255f3efffbf9b7b5b4a1227a4a95bb80bf69f0249c9a76a283b9ae05697cb33aceafc47eec63477ffa95c8544274790e
7
- data.tar.gz: 320f7a39295e8a9c29cf33f002e3cf03436a9b91d027320af3ce96114f8dbf9899a08b30b2e95fd2c6d423d6f1a68d8c516c5aa07bda2c58155b9323728415e2
6
+ metadata.gz: 241b74370dd846929cccb2fdde19960689d05ce6a7a31c863ea331b6450ce57ba0a88042abb2ecbc588cf38229356e82f43a3d16496513311445aa2787ff40e9
7
+ data.tar.gz: 528266324133acf97320be51b0f8f4f2b3e99907e2ff3a0c620b5d7e41cfa3339bb7d00bfeb3d915111fbfaa7a966100f20ee723f56ada32d0adf40572d67f0b
@@ -9,13 +9,13 @@ module OpeningHoursConverter
9
9
  VENDREDI: 4,
10
10
  SAMEDI: 5,
11
11
  DIMANCHE: 6
12
- }
13
- OSM_DAYS = [ "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su" ]
14
- IRL_DAYS = [ "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche" ]
15
- OSM_MONTHS = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
16
- IRL_MONTHS = [ "Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre",
17
- "Octobre", "Novembre", "Décembre" ]
18
- MONTH_END_DAY = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
12
+ }.freeze
13
+ OSM_DAYS = %w[Mo Tu We Th Fr Sa Su].freeze
14
+ IRL_DAYS = %w[Lundi Mardi Mercredi Jeudi Vendredi Samedi Dimanche].freeze
15
+ OSM_MONTHS = %w[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec].freeze
16
+ IRL_MONTHS = %W[Janvier Fevrier Mars Avril Mai Juin Juillet Aout Septembre
17
+ Octobre Novembre D\u00E9cembre].freeze
18
+ MONTH_END_DAY = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].freeze
19
19
  MINUTES_MAX = 1440
20
20
  DAYS_MAX = 6
21
21
  YEAR_DAYS_MAX = 365
@@ -5,7 +5,7 @@ module OpeningHoursConverter
5
5
  include Constants
6
6
  attr_reader :day_start, :day_end, :start, :end, :is_off
7
7
 
8
- def initialize(day_start, min_start, day_end=0, min_end=0, is_off=false)
8
+ def initialize(day_start, min_start, day_end = 0, min_end = 0, is_off = false)
9
9
  @day_start = day_start
10
10
  @day_end = day_end
11
11
  @start = min_start
@@ -23,9 +23,9 @@ module OpeningHoursConverter
23
23
  year_start = year
24
24
  month_start = month
25
25
  day_start = day
26
- elsif day_bool && year_start >= 0 && month == 11 && day == 30 && years[year+1].nil?
26
+ elsif day_bool && year_start >= 0 && month == 11 && day == 30 && years[year + 1].nil?
27
27
 
28
- result << { start: DateTime.new(year_start, month_start+1, day_start+1), end: DateTime.new(year, 12, 31)}
28
+ result << { start: DateTime.new(year_start, month_start + 1, day_start + 1), end: DateTime.new(year, 12, 31) }
29
29
 
30
30
  year_start = -1
31
31
  month_start = -1
@@ -33,18 +33,18 @@ module OpeningHoursConverter
33
33
  elsif !day_bool && year_start >= 0
34
34
  end_res = {}
35
35
 
36
- if day == 0
37
- if month == 0
38
- end_res = DateTime.new(year-1, 12, 31)
39
- else
40
- end_res = DateTime.new(year, month, MONTH_END_DAY[month-1])
41
- end
42
- else
36
+ end_res = if day == 0
37
+ if month == 0
38
+ DateTime.new(year - 1, 12, 31)
39
+ else
40
+ DateTime.new(year, month, MONTH_END_DAY[month - 1])
41
+ end
42
+ else
43
43
 
44
- end_res = DateTime.new(year, month+1, day)
45
- end
44
+ DateTime.new(year, month + 1, day)
45
+ end
46
46
 
47
- result << { start: DateTime.new(year_start, month_start+1, day_start+1), end: end_res }
47
+ result << { start: DateTime.new(year_start, month_start + 1, day_start + 1), end: end_res }
48
48
  year_start = -1
49
49
  month_start = -1
50
50
  day_start = -1
@@ -56,8 +56,7 @@ module OpeningHoursConverter
56
56
  date_ranges_array << result
57
57
  end
58
58
 
59
-
60
- return date_ranges_array
59
+ date_ranges_array
61
60
  end
62
61
 
63
62
  def get_time_iterator(date_ranges)
@@ -70,7 +69,6 @@ module OpeningHoursConverter
70
69
  date_ranges_array = get_iterator(date_ranges)
71
70
  datetime_result = []
72
71
 
73
-
74
72
  date_ranges_array.each_with_index do |result, index|
75
73
  result.each do |interval|
76
74
  (interval[:start]..interval[:end]).each do |day|
@@ -79,20 +77,17 @@ module OpeningHoursConverter
79
77
  year_ph = PublicHoliday.ph_for_year(year)
80
78
  end
81
79
  date_ranges[index].typical.intervals.each do |i|
82
- if !i.nil? && !i.is_off
83
- if (i.day_start..i.day_end).include?(fix_datetime_wday(day.wday)) || (is_ph && year_ph.include?(Time.new(day.year, day.month, day.day)))
84
- itr = { start: Time.new(day.year, day.month, day.day, i.start/60, i.start%60),
85
- end: Time.new(day.year, day.month, day.day, i.end/60, i.end%60) }
86
- datetime_result << itr unless datetime_result.include?(itr)
87
- end
88
- end
80
+ next unless !i.nil? && !i.is_off
81
+ next unless (i.day_start..i.day_end).cover?(fix_datetime_wday(day.wday)) || (is_ph && year_ph.include?(Time.new(day.year, day.month, day.day)))
82
+ itr = { start: Time.new(day.year, day.month, day.day, i.start / 60, i.start % 60),
83
+ end: Time.new(day.year, day.month, day.day, i.end / 60, i.end % 60) }
84
+ datetime_result << itr unless datetime_result.include?(itr)
89
85
  end
90
86
  end
91
87
  end
92
88
  end
93
89
 
94
- datetime_result.sort {|a,b| a[:start] <=> b[:start]}
95
-
90
+ datetime_result.sort_by { |a| a[:start] }
96
91
  end
97
92
 
98
93
  def get_datetime_iterator(date_ranges)
@@ -103,67 +98,63 @@ module OpeningHoursConverter
103
98
  result.each do |interval|
104
99
  (interval[:start]..interval[:end]).each do |day|
105
100
  date_ranges[index].typical.intervals.each do |i|
106
- if (i.day_start..i.day_end).include?(fix_datetime_wday(day.wday))
107
- datetime_result << { start: DateTime.new(day.year, day.month, day.day, i.start/60, i.start%60),
108
- end: DateTime.new(day.year, day.month, day.day, i.end/60, i.end%60) }
101
+ if (i.day_start..i.day_end).cover?(fix_datetime_wday(day.wday))
102
+ datetime_result << { start: DateTime.new(day.year, day.month, day.day, i.start / 60, i.start % 60),
103
+ end: DateTime.new(day.year, day.month, day.day, i.end / 60, i.end % 60) }
109
104
  end
110
105
  end
111
106
  end
112
107
  end
113
108
  end
114
109
 
115
- datetime_result.sort {|a,b| a[:start] <=> b[:start]}
110
+ datetime_result.sort_by { |a| a[:start] }
116
111
  end
117
112
 
118
-
119
-
120
113
  def fix_datetime_wday(d)
121
- d==0 ? 6 : d-1
114
+ d == 0 ? 6 : d - 1
122
115
  end
123
116
 
124
117
  # A partir d'une string OH et d'une DateTime (= now par défaut), renvoyer le current state (début / fin / commentaire)
125
- def state(opening_hours_string, time=Time.now)
118
+ def state(opening_hours_string, time = Time.now)
126
119
  date_ranges = OpeningHoursConverter::OpeningHoursParser.new.parse(opening_hours_string)
127
120
  ti = get_time_iterator(date_ranges)
128
121
  ti.each do |interval|
129
122
  return interval if interval[:start] <= time && interval[:end] >= time
130
123
  end
131
- return false
124
+ false
132
125
  end
133
126
 
134
127
  # A partir d'une string OH et d'une DateTime (= now par défaut), renvoyer le prochain state (début / fin / commentaire - nextState dans opening_hours.js) permettant d'afficher à l'utilisateur le prochain événement (ouverture/fermeture)
135
- def next_state(opening_hours_string, time=Time.now)
128
+ def next_state(opening_hours_string, time = Time.now)
136
129
  date_ranges = OpeningHoursConverter::OpeningHoursParser.new.parse(opening_hours_string)
137
130
  ti = get_time_iterator(date_ranges)
138
131
  ti.each_with_index do |interval, index|
139
- return {end: interval[:end]} if interval[:start] <= time && interval[:end] >= time
140
- return {start: interval[:start]} if interval[:start] > time && ti[index-1][:end] <= time
132
+ return { end: interval[:end] } if interval[:start] <= time && interval[:end] >= time
133
+ return { start: interval[:start] } if interval[:start] > time && ti[index - 1][:end] <= time
141
134
  end
142
- return false
135
+ false
143
136
  end
144
137
 
145
-
146
- def next_period(opening_hours_string, time=Time.now)
138
+ def next_period(opening_hours_string, time = Time.now)
147
139
  date_ranges = OpeningHoursConverter::OpeningHoursParser.new.parse(opening_hours_string)
148
140
  ti = get_time_iterator(date_ranges)
149
141
  ti.each_with_index do |interval, index|
150
- return ti[index+1] if interval[:start] <= time && interval[:end] >= time
151
- return interval if interval[:start] > time && ti[index-1][:end] <= time
142
+ return ti[index + 1] if interval[:start] <= time && interval[:end] >= time
143
+ return interval if interval[:start] > time && ti[index - 1][:end] <= time
152
144
  end
153
- return false
145
+ false
154
146
  end
155
147
 
156
148
  # A partir d'une string OH et d'une DateTime (= now par défaut), déterminer cela correspond à une période d'ouverture : renvoyer un boolean.
157
- def is_opened?(opening_hours_string, time=Time.now)
149
+ def is_opened?(opening_hours_string, time = Time.now)
158
150
  date_ranges = OpeningHoursConverter::OpeningHoursParser.new.parse(opening_hours_string)
159
151
  ti = get_time_iterator(date_ranges)
160
152
  ti.each do |interval|
161
153
  return true if interval[:start] <= time && interval[:end] >= time
162
154
  end
163
- return false
155
+ false
164
156
  end
165
157
 
166
-
167
158
  def datetime_to_time(datetime)
168
159
  Time.new(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.min, datetime.sec, datetime.zone)
169
160
  end
@@ -171,6 +162,5 @@ module OpeningHoursConverter
171
162
  def time_to_datetime(time)
172
163
  DateTime.new(time.year, time.month, time.day, time.hour, time.min, time.sec, Rational(time.gmt_offset / 3600, 24))
173
164
  end
174
-
175
165
  end
176
166
  end
@@ -14,115 +14,100 @@ module OpeningHoursConverter
14
14
  off_day_ph = false
15
15
 
16
16
  date_ranges.each_with_index do |date_range, date_range_index|
17
- if !date_range.nil?
18
- if date_range.typical.intervals.length != 1
19
- date_range.typical.intervals.each_with_index do |interval, interval_id|
20
- if interval&.day_start == -2 && interval&.day_start == interval&.day_end
21
- if interval.is_off
22
- off_day_ph = true
23
- else
24
- day_ph = true
25
- end
26
- date_range.typical.remove_interval(interval_id)
27
- end
17
+ next unless !date_range.nil?
18
+ if date_range.typical.intervals.length != 1
19
+ date_range.typical.intervals.each_with_index do |interval, interval_id|
20
+ next unless interval&.day_start == -2 && interval&.day_start == interval&.day_end
21
+ if interval.is_off
22
+ off_day_ph = true
23
+ else
24
+ day_ph = true
28
25
  end
26
+ date_range.typical.remove_interval(interval_id)
29
27
  end
28
+ end
30
29
 
31
- range_general = nil
32
- range_general_for = nil
33
- range_general_id = date_range_index - 1
34
-
35
- while range_general_id >= 0 && range_general.nil?
36
- if !date_range.nil?
37
- general_for = date_ranges[range_general_id].is_general_for?(date_range)
38
- if date_ranges[range_general_id].has_same_typical?(date_range) && (date_ranges[range_general_id].wide_interval.equals(date_range.wide_interval) || general_for)
39
- range_general = range_general_id
40
- elsif general_for && date_ranges[range_general_id].defines_typical_week? && date_range.defines_typical_week?
41
- range_general_for = range_general_id
42
- end
30
+ range_general = nil
31
+ range_general_for = nil
32
+ range_general_id = date_range_index - 1
33
+
34
+ while range_general_id >= 0 && range_general.nil?
35
+ if !date_range.nil?
36
+ general_for = date_ranges[range_general_id].is_general_for?(date_range)
37
+ if date_ranges[range_general_id].has_same_typical?(date_range) && (date_ranges[range_general_id].wide_interval.equals(date_range.wide_interval) || general_for)
38
+ range_general = range_general_id
39
+ elsif general_for && date_ranges[range_general_id].defines_typical_week? && date_range.defines_typical_week?
40
+ range_general_for = range_general_id
43
41
  end
44
- range_general_id -= 1
45
42
  end
43
+ range_general_id -= 1
44
+ end
46
45
 
47
- if date_range_index == 0 || range_general.nil?
48
- if date_range.typical&.intervals&.length == 1 && date_range.typical&.intervals[0].day_start == -2 && date_range.typical&.intervals[0].day_end == -2
49
- oh_rules = build_holiday(date_range)
50
- elsif date_range.defines_typical_week?
51
- if !range_general_for.nil?
52
- oh_rules = build_week_diff(date_range, date_ranges[range_general_for])
53
- else
54
- oh_rules = build_week(date_range)
55
- end
56
- else
57
- oh_rules = build_day(date_range)
58
- end
59
-
60
-
46
+ next unless date_range_index == 0 || range_general.nil?
47
+ if date_range.typical&.intervals&.length == 1 && date_range.typical&.intervals[0].day_start == -2 && date_range.typical&.intervals[0].day_end == -2
48
+ oh_rules = build_holiday(date_range)
49
+ elsif date_range.defines_typical_week?
50
+ oh_rules = if !range_general_for.nil?
51
+ build_week_diff(date_range, date_ranges[range_general_for])
52
+ else
53
+ build_week(date_range)
54
+ end
55
+ else
56
+ oh_rules = build_day(date_range)
57
+ end
61
58
 
62
- oh_rules.each_with_index do |rule, i|
63
- oh_rules[i].add_comment(date_range.comment)
64
- end
59
+ oh_rules.each_with_index do |_rule, i|
60
+ oh_rules[i].add_comment(date_range.comment)
61
+ end
65
62
 
63
+ oh_rules.map do |oh_rule|
64
+ oh_rule_added = false
65
+ rule_index = 0
66
66
 
67
- oh_rules.map do |oh_rule|
68
- oh_rule_added = false
69
- rule_index = 0
70
-
71
- while !oh_rule_added && rule_index < rules.length
72
- if rules[rule_index].same_time?(oh_rule) && !rules[rule_index].equals(oh_rule) && rules[rule_index].comment == oh_rule.comment
73
- begin
74
- for date_id in 0...oh_rule.date.length
75
- rules[rule_index].add_date(oh_rule.date[date_id])
76
- end
77
- oh_rule_added = true
78
- rescue Exception => e
79
- puts e
80
- if oh_rule.date[0].wide_interval.type == "holiday" && oh_rule.date[0].wide_interval.get_time_selector == "PH"
81
- rules[rule_index].add_ph_weekday
82
- oh_rule_added = true
83
- elsif rules[rule_index].date[0].wide_interval.type == "holiday" && rules[rule_index].date[0].wide_interval.get_time_selector == "PH"
84
- oh_rule.add_ph_weekday
85
- rules[rule_index] = oh_rule
86
- oh_rule_added = true
87
- else
88
- rule_index += 1
89
- end
90
- end
67
+ while !oh_rule_added && rule_index < rules.length
68
+ if rules[rule_index].same_time?(oh_rule) && !rules[rule_index].equals(oh_rule) && rules[rule_index].comment == oh_rule.comment
69
+ begin
70
+ for date_id in 0...oh_rule.date.length
71
+ rules[rule_index].add_date(oh_rule.date[date_id])
72
+ end
73
+ oh_rule_added = true
74
+ rescue Exception => e
75
+ puts e
76
+ if oh_rule.date[0].wide_interval.type == 'holiday' && oh_rule.date[0].wide_interval.get_time_selector == 'PH'
77
+ rules[rule_index].add_ph_weekday
78
+ oh_rule_added = true
79
+ elsif rules[rule_index].date[0].wide_interval.type == 'holiday' && rules[rule_index].date[0].wide_interval.get_time_selector == 'PH'
80
+ oh_rule.add_ph_weekday
81
+ rules[rule_index] = oh_rule
82
+ oh_rule_added = true
91
83
  else
92
- rule_index+=1
84
+ rule_index += 1
93
85
  end
94
86
  end
87
+ else
88
+ rule_index += 1
89
+ end
90
+ end
95
91
 
96
- if day_ph
97
- oh_rule.add_ph_weekday
98
- end
99
-
92
+ oh_rule.add_ph_weekday if day_ph
100
93
 
101
- if !oh_rule_added
102
- rules << oh_rule
103
- end
94
+ rules << oh_rule if !oh_rule_added
104
95
 
105
- if off_day_ph
106
- rules += build_off_holiday(date_range)
107
- end
96
+ rules += build_off_holiday(date_range) if off_day_ph
108
97
 
109
- if oh_rule == oh_rules.last && oh_rule.has_overwritten_weekday?
110
- oh_rule_over = OpeningHoursConverter::OpeningHoursRule.new
98
+ next unless oh_rule == oh_rules.last && oh_rule.has_overwritten_weekday?
99
+ oh_rule_over = OpeningHoursConverter::OpeningHoursRule.new
111
100
 
112
- oh_rule.date.each do |date|
113
- oh_rule_over.add_date(OpeningHoursConverter::OpeningHoursDate.new(date.wide_interval, date.weekdays_over))
114
- end
115
- oh_rule_over.add_time(OpeningHoursConverter::OpeningHoursTime.new)
116
- oh_rules << oh_rule_over
117
- end
118
- end
101
+ oh_rule.date.each do |date|
102
+ oh_rule_over.add_date(OpeningHoursConverter::OpeningHoursDate.new(date.wide_interval, date.weekdays_over))
119
103
  end
104
+ oh_rule_over.add_time(OpeningHoursConverter::OpeningHoursTime.new)
105
+ oh_rules << oh_rule_over
120
106
  end
121
107
  end
122
108
 
123
-
124
- result = ""
125
- if rules.length == 0
109
+ result = ''
110
+ if rules.empty?
126
111
  date_ranges.each do |dr|
127
112
  result += "#{dr.wide_interval.get_time_selector} off"
128
113
  end
@@ -130,32 +115,29 @@ module OpeningHoursConverter
130
115
  result += rules.map(&:get).join('; ')
131
116
  end
132
117
 
133
- return result.strip
118
+ result.strip
134
119
  end
135
120
 
136
121
  def build_off_holiday(date_range)
137
-
138
122
  start_year = date_range.wide_interval.start&.key?(:year) ? date_range.wide_interval.start[:year] : date_range.wide_interval.start
139
123
  end_year = date_range.wide_interval.end&.key?(:year) ? date_range.wide_interval.end[:year] : date_range.wide_interval.end
140
124
 
141
- date_range = OpeningHoursConverter::DateRange.new(OpeningHoursConverter::WideInterval.new.holiday("PH", start_year, end_year))
125
+ date_range = OpeningHoursConverter::DateRange.new(OpeningHoursConverter::WideInterval.new.holiday('PH', start_year, end_year))
142
126
 
143
127
  rule = OpeningHoursConverter::OpeningHoursRule.new
144
128
  date = OpeningHoursConverter::OpeningHoursDate.new(date_range.wide_interval, [-1])
145
129
  rule.add_date(date)
146
130
  rule.is_defined_off = true
147
131
 
148
- return [ rule ]
132
+ [rule]
149
133
  end
150
134
 
151
135
  def build_holiday(date_range)
152
-
153
136
  start_year = date_range.wide_interval.start&.key?(:year) ? date_range.wide_interval.start[:year] : date_range.wide_interval.start
154
137
  end_year = date_range.wide_interval.end&.key?(:year) ? date_range.wide_interval.end[:year] : date_range.wide_interval.end
155
138
 
156
-
157
139
  intervals = date_range.typical.get_intervals(true)
158
- date_range = OpeningHoursConverter::DateRange.new(OpeningHoursConverter::WideInterval.new.holiday("PH", start_year, end_year))
140
+ date_range = OpeningHoursConverter::DateRange.new(OpeningHoursConverter::WideInterval.new.holiday('PH', start_year, end_year))
159
141
 
160
142
  for i in 0..6
161
143
  intervals.each do |interval|
@@ -175,8 +157,7 @@ module OpeningHoursConverter
175
157
  end
176
158
  end
177
159
 
178
-
179
- return [ rule ]
160
+ [rule]
180
161
  end
181
162
 
182
163
  def build_day(date_range)
@@ -193,7 +174,7 @@ module OpeningHoursConverter
193
174
  end
194
175
  end
195
176
 
196
- return [ rule ]
177
+ [rule]
197
178
  end
198
179
 
199
180
  def build_week(date_range)
@@ -218,22 +199,19 @@ module OpeningHoursConverter
218
199
  else
219
200
  md_off += 1
220
201
  end
221
- if !merged
222
- result << days[index]
223
- end
202
+ result << days[index] if !merged
224
203
  end
225
204
  elsif days_status[index] <= 0 && days_status[index] > -8
226
205
  days_status[index] = index + 1
227
206
  last_same_day = index
228
207
  same_day_count = 1
229
208
 
230
- for j in (index+1)...days.length do
231
- if day.same_time?(days[j])
232
- days_status[j] = index + 1
233
- day.add_weekday(j)
234
- last_same_day = j
235
- same_day_count += 1
236
- end
209
+ for j in (index + 1)...days.length do
210
+ next unless day.same_time?(days[j])
211
+ days_status[j] = index + 1
212
+ day.add_weekday(j)
213
+ last_same_day = j
214
+ same_day_count += 1
237
215
  end
238
216
  if same_day_count == 1
239
217
  result << day
@@ -246,22 +224,19 @@ module OpeningHoursConverter
246
224
  end
247
225
  end
248
226
  end
249
- if result == [] && days_status == [8, 8, 8, 8, 8, 8, 8]
250
- result = days
251
- end
227
+ result = days if result == [] && days_status == [8, 8, 8, 8, 8, 8, 8]
252
228
 
253
229
  result = merge_days(result)
254
230
 
255
- return result
231
+ result
256
232
  end
257
233
 
258
234
  def build_week_diff(date_range, general_date_range)
259
235
  intervals = date_range.typical.get_intervals_diff(general_date_range.typical)
260
236
  days = create_time_intervals(
261
237
  date_range.wide_interval,
262
- intervals[:open])
263
-
264
-
238
+ intervals[:open]
239
+ )
265
240
 
266
241
  intervals[:closed].each do |interval|
267
242
  for i in interval.day_start..interval.day_end do
@@ -287,10 +262,8 @@ module OpeningHoursConverter
287
262
  end
288
263
  end
289
264
 
290
- if !merged
291
- result << day
292
- end
293
- elsif day.is_off? && day.time.length == 0
265
+ result << day if !merged
266
+ elsif day.is_off? && day.time.empty?
294
267
  days_status[index] = 8
295
268
  elsif days_status[index] <= 0 && days_status[index] > -8
296
269
  days_status[index] = index + 1
@@ -299,12 +272,11 @@ module OpeningHoursConverter
299
272
  result << day
300
273
 
301
274
  for j in (index + 1)...days.length do
302
- if day.same_time?(days[j])
303
- days_status[j] = index + 1
304
- day.add_weekday(j)
305
- last_same_day = j
306
- same_day_count += 1
307
- end
275
+ next unless day.same_time?(days[j])
276
+ days_status[j] = index + 1
277
+ day.add_weekday(j)
278
+ last_same_day = j
279
+ same_day_count += 1
308
280
  end
309
281
 
310
282
  if same_day_count == 1
@@ -314,12 +286,9 @@ module OpeningHoursConverter
314
286
  result << day
315
287
  elsif same_day_count > 2
316
288
  for j in (index + 1)...last_same_day do
317
- if days_status[j] == 0
318
- days_status[j] = -index - 1
319
- if days[j].time.length > 0
320
- day.add_overwritten_weekday(j)
321
- end
322
- end
289
+ next unless days_status[j] == 0
290
+ days_status[j] = -index - 1
291
+ day.add_overwritten_weekday(j) if !days[j].time.empty?
323
292
  end
324
293
  day.add_weekday(last_same_day)
325
294
  result << day
@@ -328,11 +297,11 @@ module OpeningHoursConverter
328
297
  end
329
298
  end
330
299
  result = merge_days(result)
331
- return result
300
+ result
332
301
  end
333
302
 
334
303
  def merge_days(rules)
335
- return rules if rules.length == 0
304
+ return rules if rules.empty?
336
305
  result = []
337
306
  result << rules[0]
338
307
  dm = 0
@@ -350,51 +319,49 @@ module OpeningHoursConverter
350
319
  end
351
320
  dm += 1
352
321
  end
353
- if !date_merged
354
- result << rules[d]
355
- end
322
+ result << rules[d] if !date_merged
356
323
  end
357
324
 
358
- return result
325
+ result
359
326
  end
360
327
 
361
328
  def create_time_intervals(wide_interval, intervals)
362
329
  days = []
363
330
  for i in 0...7
364
331
  days << OpeningHoursConverter::OpeningHoursRule.new
365
- days[i].add_date(OpeningHoursConverter::OpeningHoursDate.new(wide_interval, [ i ]))
332
+ days[i].add_date(OpeningHoursConverter::OpeningHoursDate.new(wide_interval, [i]))
366
333
  end
367
334
 
368
335
  intervals.each do |interval|
369
- if !interval.nil?
370
- begin
371
- if interval.day_start == interval.day_end
372
- days[interval.day_start].add_time(OpeningHoursConverter::OpeningHoursTime.new(interval.start, interval.end))
373
- days[interval.day_start].is_defined_off = days[interval.day_start].is_defined_off ? true : interval.is_off
374
- elsif interval.day_end - interval.day_start == 1
375
- days[interval.day_start].add_time(OpeningHoursConverter::OpeningHoursTime.new(interval.start, MINUTES_MAX))
376
- days[interval.day_start].is_defined_off = days[interval.day_start].is_defined_off ? true : interval.is_off
377
- days[interval.day_end].add_time(OpeningHoursConverter::OpeningHoursTime.new(0, interval.end))
378
- days[interval.day_end].is_defined_off = days[interval.day_end].is_defined_off ? true : interval.is_off
379
- else
380
- for j in interval.day_start..interval.day_end
381
- days[j].is_defined_off = days[j].is_defined_off ? true : interval.is_off
382
- if j == interval.day_start
383
- days[j].add_time(OpeningHoursConverter::OpeningHoursTime.new(interval.start, MINUTES_MAX))
384
- elsif j == interval.day_end
385
- days[j].add_time(OpeningHoursConverter::OpeningHoursTime.new(0, interval.end))
386
- else
387
- days[j].add_time(OpeningHoursConverter::OpeningHoursTime.new(0, MINUTES_MAX))
388
- end
336
+ next if interval.nil?
337
+
338
+ begin
339
+ if interval.day_start == interval.day_end
340
+ days[interval.day_start].add_time(OpeningHoursConverter::OpeningHoursTime.new(interval.start, interval.end))
341
+ days[interval.day_start].is_defined_off = days[interval.day_start].is_defined_off ? true : interval.is_off
342
+ elsif interval.day_end - interval.day_start == 1
343
+ days[interval.day_start].add_time(OpeningHoursConverter::OpeningHoursTime.new(interval.start, MINUTES_MAX))
344
+ days[interval.day_start].is_defined_off = days[interval.day_start].is_defined_off ? true : interval.is_off
345
+ days[interval.day_end].add_time(OpeningHoursConverter::OpeningHoursTime.new(0, interval.end))
346
+ days[interval.day_end].is_defined_off = days[interval.day_end].is_defined_off ? true : interval.is_off
347
+ else
348
+ for j in interval.day_start..interval.day_end
349
+ days[j].is_defined_off = days[j].is_defined_off ? true : interval.is_off
350
+ if j == interval.day_start
351
+ days[j].add_time(OpeningHoursConverter::OpeningHoursTime.new(interval.start, MINUTES_MAX))
352
+ elsif j == interval.day_end
353
+ days[j].add_time(OpeningHoursConverter::OpeningHoursTime.new(0, interval.end))
354
+ else
355
+ days[j].add_time(OpeningHoursConverter::OpeningHoursTime.new(0, MINUTES_MAX))
389
356
  end
390
357
  end
391
- rescue Exception => e
392
- puts e
393
358
  end
359
+ rescue Exception => e
360
+ puts e
394
361
  end
395
362
  end
396
363
 
397
- return days
364
+ days
398
365
  end
399
366
  end
400
367
  end