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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f54fd5ddf40e3463f208523f3e4df1583a28157b1b4102c5c972e44b45f6789c
4
- data.tar.gz: 63e8c1117bd05c79e58144815c89235f0ec8088b817a78e45f25feaf62dcf0f3
3
+ metadata.gz: '08d64cb65cb3b261526debe5bbac2139dc2d18ccfea137eeceaddb5c221a7a09'
4
+ data.tar.gz: a6553952b6ea0c7d3f0e87f916a315c7ab9f022bb5c8cb58accae49a32f8d283
5
5
  SHA512:
6
- metadata.gz: 8a4ad268e1c8c0f8e2e12bcf8b523eab79c59a910b41ce2c1c6c7f052359b34e9ecee1f63c541191104bd605a2efafc9637e9169804e5046b92339d14d623f18
7
- data.tar.gz: 26114741c15bc0f79f9722526e7f2acbb91fa9baecb00d8bbf9b4b90a03d8b6a2dd956937bc4b989f27273c4142afa1351fef338a26bb7f63db4db9cdf0d7025
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 |week_index|
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 |week_index|
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opening_hours_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.5
4
+ version: 1.13.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ziserman Martin