opening_hours_converter 1.13.5 → 1.13.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/opening_hours_converter/week_index.rb +14 -0
- data/lib/opening_hours_converter/year.rb +2 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08d64cb65cb3b261526debe5bbac2139dc2d18ccfea137eeceaddb5c221a7a09'
|
4
|
+
data.tar.gz: a6553952b6ea0c7d3f0e87f916a315c7ab9f022bb5c8cb58accae49a32f8d283
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7467758597633280c3863cead517d31fa18ad63dbaf8fca05d5236da2d63001e360ba3ade52f054774436da8e14787fd02e5af330007cebeebc152a96359732e
|
7
|
+
data.tar.gz: 348168fd8f07315a942162d8313736f8237a196e4fdc84ed150812d0751aa83344c0740fa5330ef59b5499bd6857793ed001625e1c4f56c020c0d28a60138104
|
@@ -6,6 +6,20 @@ module OpeningHoursConverter
|
|
6
6
|
include Constants
|
7
7
|
extend Utils
|
8
8
|
|
9
|
+
def self.weeks_from_index(array_of_indexes, year = Time.now.year)
|
10
|
+
array_of_indexes.flat_map do |index_or_range|
|
11
|
+
if index_or_range.is_a?(Hash)
|
12
|
+
index_or_range[:from].step(index_or_range[:to], index_or_range[:modifier]).map do |index|
|
13
|
+
week_from_index(index, year)
|
14
|
+
end
|
15
|
+
elsif index_or_range.is_a?(Integer)
|
16
|
+
week_from_index(index_or_range, year)
|
17
|
+
else
|
18
|
+
raise ArgumentError, "#{index_or_range} in #{array_of_indexes} is neither an integer nor a Hash"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
9
23
|
def self.week_from_index(index, year = Time.now.year)
|
10
24
|
raise unless index >= 1
|
11
25
|
|
@@ -230,8 +230,7 @@ module OpeningHoursConverter
|
|
230
230
|
for year in (DateTime.now.year)..(DateTime.now.year + 1)
|
231
231
|
if wide_interval.type == 'week'
|
232
232
|
years[year] ||= Array.new(OSM_MONTHS.length) { |i| Array.new(MONTH_END_DAY[i]) { false } }
|
233
|
-
wide_interval.indexes.each do |
|
234
|
-
interval = WeekIndex.week_from_index(week_index, year)
|
233
|
+
WeekIndex.weeks_from_index(wide_interval.indexes, year).each do |interval|
|
235
234
|
(interval[:from]..interval[:to]).each do |day|
|
236
235
|
years[year][day.month - 1][day.day - 1] = true
|
237
236
|
end
|
@@ -373,8 +372,7 @@ module OpeningHoursConverter
|
|
373
372
|
end
|
374
373
|
elsif wide_interval.type == "week"
|
375
374
|
year = wide_interval.start&.dig(:year) || Time.now.year # can't process weeks with undefined year
|
376
|
-
wide_interval.indexes.each do |
|
377
|
-
interval = WeekIndex.week_from_index(week_index, year)
|
375
|
+
WeekIndex.weeks_from_index(wide_interval.indexes, year).each do |interval|
|
378
376
|
(interval[:from]..interval[:to]).each do |day|
|
379
377
|
years[year][day.month - 1][day.day - 1] = true
|
380
378
|
end
|