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,23 +17,22 @@ module OpeningHoursConverter
17
17
  end
18
18
 
19
19
  def get_weekdays
20
- result = ""
21
- wd = @weekdays.concat(@weekdays_over).sort.uniq
20
+ result = ''
21
+ weekdays = @weekdays.concat(@weekdays_over).sort.uniq
22
22
 
23
- if wd.length > 0 && wd[0] == -2
24
- result = "PH"
25
- wd.shift
23
+ if !weekdays.empty? && weekdays[0] == -2
24
+ result = 'PH'
25
+ weekdays.shift
26
26
  end
27
27
 
28
-
29
- if wd.length > 0 && wd.include?(6) && wd.include?(0) && (wd.include?(5) || wd.include?(1))
30
- start_we = 6
31
- i = wd.length - 2
28
+ if !weekdays.empty? && weekdays.include?(6) && weekdays.include?(0) && (weekdays.include?(5) || weekdays.include?(1))
29
+ start_week_end = 6
30
+ i = weekdays.length - 2
32
31
  stop_looking = false
33
32
 
34
33
  while !stop_looking && i >= 0
35
- if wd[i] == wd[i+1] - 1
36
- start_we = wd[i]
34
+ if weekdays[i] == weekdays[i + 1] - 1
35
+ start_week_end = weekdays[i]
37
36
  i -= 1
38
37
  else
39
38
  stop_looking = true
@@ -42,71 +41,67 @@ module OpeningHoursConverter
42
41
 
43
42
  i = 1
44
43
  stop_looking = false
45
- end_we = 0
44
+ end_week_end = 0
46
45
 
47
- while !stop_looking && i < wd.length
48
- if wd[i-1] == wd[i] - 1
49
- end_we = wd[i]
46
+ while !stop_looking && i < weekdays.length
47
+ if weekdays[i - 1] == weekdays[i] - 1
48
+ end_week_end = weekdays[i]
50
49
  i += 1
51
50
  else
52
51
  stop_looking = true
53
52
  end
54
53
  end
55
54
 
56
- length = 7 - start_we + end_we + 1
55
+ length = 7 - start_week_end + end_week_end + 1
57
56
 
58
- if length >= 3 && start_we > end_we
59
- if result.length > 0
60
- result += ","
61
- end
62
- result += "#{OSM_DAYS[start_we]}-#{OSM_DAYS[end_we]}"
57
+ if length >= 3 && start_week_end > end_week_end
58
+ result += ',' if !result.empty?
59
+ result += "#{OSM_DAYS[start_week_end]}-#{OSM_DAYS[end_week_end]}"
63
60
 
64
- j=0
65
- while j < wd.length
66
- if wd[j] <= end_we || wd[j] >= start_we
67
- wd.slice!(j, 1)
61
+ j = 0
62
+ while j < weekdays.length
63
+ if weekdays[j] <= end_week_end || weekdays[j] >= start_week_end
64
+ weekdays.slice!(j, 1)
68
65
  else
69
- j+=1
66
+ j += 1
70
67
  end
71
68
  end
72
69
  end
73
70
  end
74
71
 
75
- if wd.length > 1 || (wd.length == 1 && wd[0] != -1)
76
- result += result.length > 0 ? ",#{OSM_DAYS[wd[0]]}" : OSM_DAYS[wd[0]]
77
- first_in_row = wd[0]
78
- for i in 1...wd.length
79
- if wd[i-1] != wd[i] - 1
80
- if first_in_row != wd[i-1]
81
- if wd[i-1] - first_in_row == 1
82
- result += ",#{OSM_DAYS[wd[i-1]]}"
83
- else
84
- result += "-#{OSM_DAYS[wd[i-1]]}"
85
- end
86
- end
87
- result += ",#{OSM_DAYS[wd[i]]}"
88
- first_in_row = wd[i]
89
- elsif i == wd.length - 1
90
- if wd[i] - first_in_row == 1
91
- result += ",#{OSM_DAYS[wd[i]]}"
92
- else
93
- result += "-#{OSM_DAYS[wd[i]]}"
72
+ if weekdays.length > 1 || (weekdays.length == 1 && weekdays[0] != -1)
73
+ result += !result.empty? ? ",#{OSM_DAYS[weekdays[0]]}" : OSM_DAYS[weekdays[0]]
74
+ first_in_row = weekdays[0]
75
+ for i in 1...weekdays.length
76
+ if weekdays[i - 1] != weekdays[i] - 1
77
+ if first_in_row != weekdays[i - 1]
78
+ result += if weekdays[i - 1] - first_in_row == 1
79
+ ",#{OSM_DAYS[weekdays[i - 1]]}"
80
+ else
81
+ "-#{OSM_DAYS[weekdays[i - 1]]}"
82
+ end
94
83
  end
84
+ result += ",#{OSM_DAYS[weekdays[i]]}"
85
+ first_in_row = weekdays[i]
86
+ elsif i == weekdays.length - 1
87
+ result += if weekdays[i] - first_in_row == 1
88
+ ",#{OSM_DAYS[weekdays[i]]}"
89
+ else
90
+ "-#{OSM_DAYS[weekdays[i]]}"
91
+ end
95
92
  end
96
93
  end
97
94
  end
98
95
 
99
- if result == "Mo-Su"
100
- result = ""
101
- end
102
- return result
96
+ result = '' if result == 'Mo-Su'
97
+ result
103
98
  end
104
99
 
105
100
  def add_weekday(weekday)
106
- if !@weekdays.include?(weekday) && !@weekdays_over.include?(weekday)
107
- @weekdays << weekday
108
- @weekdays.sort!
109
- end
101
+ return if @weekdays.include?(weekday) || @weekdays_over.include?(weekday)
102
+
103
+ @weekdays << weekday
104
+ @weekdays.sort!
110
105
  end
111
106
 
112
107
  def add_ph_weekday
@@ -114,10 +109,10 @@ module OpeningHoursConverter
114
109
  end
115
110
 
116
111
  def add_overwritten_weekday(weekday)
117
- unless @weekdays_over.include?(weekday) && @weekdays_over.include?(weekday)
118
- @weekdays_over << weekday
119
- @weekdays_over.sort!
120
- end
112
+ return if @weekdays_over.include?(weekday) && @weekdays_over.include?(weekday)
113
+
114
+ @weekdays_over << weekday
115
+ @weekdays_over.sort!
121
116
  end
122
117
 
123
118
  def same_kind_as?(date)