opening_hours_converter 1.11.0 → 1.12.0

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: 8d9c36ae7cf29f7c3cc90f3fa56a1b24f3294b9201356bb3c7cecf5319857343
4
- data.tar.gz: 34079e2a3f1dbb735d5e07f9aab3a62d726cf0f7f88de29e86235a73462c5a4a
3
+ metadata.gz: e8c4565d4b2ec3935fb6ca2b3e79375d9bf3a673b10227b4555bfea65e1b6af8
4
+ data.tar.gz: 3b783952f44dfe2eebb2af35f395d9882c56e88e95286ce7f06b8622a9c48e00
5
5
  SHA512:
6
- metadata.gz: 68a659bdff345013b1c2e00df196725024792536e87b92b586c46e286f2bb8baab856d2c91564feb22c6d0969f26a1a5f781adf42e7d8f78659e3b1ef008e6e0
7
- data.tar.gz: 8f977df19ce9fe13547f5215320b1a699ee1bf40a6b2e804865b9b9aba15e8dbe74eb5ac3c0f608f76010b6768b381c0f09fa537247be8fd31c78a611eb9a10a
6
+ metadata.gz: b3f1610f8e8ce1d8ec8aad0fb2d6c6cf55262b7a12711f3fe6eed54272f7c7faf2ae71da24dd7adec516478015884a46edf04c0ee174d8739e25106cae88b6da
7
+ data.tar.gz: 63e8f01a0f42038315aef4054bcc9060def0b3cb98f269f40d767ef36abf946d06708e037b7f57217a7ba8c92993498075013e218cb4bc3ea3d2f0837552909b
@@ -27,7 +27,8 @@ module OpeningHoursConverter
27
27
  @RGX_YEAR_WEEK = /^(\d{4})(\-(\d{4}))? week ([01234]?[0-9]|5[0123])(\-([01234]?[0-9]|5[0123]))?(, ?([01234]?[0-9]|5[0123])(\-([01234]?[0-9]|5[0123]))?)*\:?$/
28
28
  @RGX_YEAR_WEEK_WITH_MODIFIER = /^(\d{4})(\-(\d{4}))? week ([01234]?[0-9]|5[0123])(\-([01234]?[0-9]|5[0123])(\/[1-9])?)?(, ?([01234]?[0-9]|5[0123])(\-([01234]?[0-9]|5[0123])(\/[1-9])?)?)*$/
29
29
  @RGX_YEAR_MONTH_DAY = /^(\d{4}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([012]?[0-9]|3[01])(\-((\d{4}) )?((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) )?([012]?[0-9]|3[01]))?\:?$/
30
- @RGX_YEAR_MULTI_MONTH_DAY = /^(\d{4}) ((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([012]?[0-9]|3[01]),?)*?$/
30
+ @RGX_YEAR_MULTI_MONTH_DAY = /^(\d{4}) ((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)( ([012]?[0-9]|3[01])(-([012]?[0-9]|3[01]))?)?,? ?)*?$/
31
+ @RGX_YEAR_MULTI_MONTH = /^(\d{4}) ((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec),? ?)*?$/
31
32
  @RGX_YEAR_MONTH = /^(\d{4}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(\-((\d{4}) )?((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)))?\:?$/
32
33
  @RGX_COMMENT = /^\"[^\"]*\"$/
33
34
  end
@@ -131,6 +132,8 @@ module OpeningHoursConverter
131
132
  months << get_month(wide_range_selector)
132
133
  elsif !(@RGX_YEAR =~ wide_range_selector).nil?
133
134
  years << get_year(wide_range_selector)
135
+ elsif !(@RGX_YEAR_MULTI_MONTH =~ wide_range_selector).nil?
136
+ months += get_year_multi_month(wide_range_selector)
134
137
  elsif !(@RGX_YEAR_MULTI_MONTH_DAY =~ wide_range_selector).nil?
135
138
  months += get_year_multi_month_day(wide_range_selector)
136
139
  elsif !(@RGX_YEAR_WEEK_WITH_MODIFIER =~ wide_range_selector).nil?
@@ -519,13 +522,48 @@ module OpeningHoursConverter
519
522
  year = wrs[0...4]
520
523
  wrs = wrs[5..wrs.length]
521
524
 
525
+ wrs.split(',').map do |wr|
526
+ month = wr[0...3]
527
+ days = wr[4...wr.length].split('-').reject { |e| e == '' }.map(&:to_i)
528
+ if days.length == 2
529
+ from = {
530
+ year: year.to_i,
531
+ month: OSM_MONTHS.find_index(wr[0...3]) + 1,
532
+ day: days[0]
533
+ }
534
+ to = {
535
+ year: year.to_i,
536
+ month: OSM_MONTHS.find_index(wr[0...3]) + 1,
537
+ day: days[1]
538
+ }
539
+ { from_day: from, to_day: to }
540
+ else
541
+ from = {
542
+ year: year.to_i,
543
+ month: OSM_MONTHS.find_index(wr[0...3]) + 1,
544
+ day: wr[4...wr.length].to_i
545
+ }
546
+ { from_day: from, to_day: from }
547
+ end
548
+ end
549
+ end
550
+
551
+ def get_year_multi_month(wrs)
552
+ year = wrs[0...4]
553
+ wrs = wrs[5..wrs.length]
554
+
522
555
  wrs.split(',').map do |wr|
523
556
  from = {
524
557
  year: year.to_i,
525
558
  month: OSM_MONTHS.find_index(wr[0...3]) + 1,
526
- day: wr[4...wr.length].to_i
559
+ day: 1
560
+ }
561
+ to = {
562
+ year: year.to_i,
563
+ month: OSM_MONTHS.find_index(wr[0...3]) + 1,
564
+ day: MONTH_END_DAY[OSM_MONTHS.find_index(wr[0...3])]
527
565
  }
528
- { from_day: from, to_day: from }
566
+ { from_day: from, to_day: to }
529
567
  end
530
568
  end
531
569
 
@@ -172,30 +172,23 @@ module OpeningHoursConverter
172
172
  else
173
173
  result.each do |selector, intervals|
174
174
  if selector == 'always'
175
- if end_before_start?(intervals)
176
- end_interval = intervals.select { |interval| interval[:start][:day] == 0 && interval[:start][:month] == 0 }.first
177
- start_interval = intervals.select { |interval| interval[:end][:day] == 30 && interval[:end][:month] == 11 }.first
175
+ intervals.each do |interval|
178
176
  str_result += ',' if !str_result.empty?
179
- str_result += "#{OSM_MONTHS[start_interval[:start][:month]]} #{start_interval[:start][:day] + 1 < 10 ? "0#{start_interval[:start][:day] + 1}" : start_interval[:start][:day] + 1}-#{OSM_MONTHS[end_interval[:end][:month]]} #{end_interval[:end][:day] + 1 < 10 ? "0#{end_interval[:end][:day] + 1}" : end_interval[:end][:day] + 1}"
180
- else
181
- intervals.each do |interval|
182
- str_result += ',' if !str_result.empty?
183
- if is_full_year?(interval)
184
- elsif starts_year?(interval) && ends_year?(interval)
185
- str_result += "#{interval[:start][:year]}-#{interval[:end][:year]}"
186
- elsif is_full_month?(interval)
187
- str_result += (OSM_MONTHS[interval[:start][:month]]).to_s
188
- elsif is_same_month?(interval)
189
- if is_same_day?(interval)
190
- str_result += "#{OSM_MONTHS[interval[:start][:month]]} #{interval[:start][:day] + 1 < 10 ? "0#{interval[:start][:day] + 1}" : interval[:start][:day] + 1}"
191
- else
192
- str_result += "#{OSM_MONTHS[interval[:start][:month]]} #{interval[:start][:day] + 1 < 10 ? "0#{interval[:start][:day] + 1}" : interval[:start][:day] + 1}-#{interval[:end][:day] + 1 < 10 ? "0#{interval[:end][:day] + 1}" : interval[:end][:day] + 1}"
193
- end
194
- elsif starts_month?(interval) && ends_month?(interval)
195
- str_result += "#{OSM_MONTHS[interval[:start][:month]]}-#{OSM_MONTHS[interval[:end][:month]]}"
177
+ if is_full_year?(interval)
178
+ elsif starts_year?(interval) && ends_year?(interval)
179
+ str_result += "#{interval[:start][:year]}-#{interval[:end][:year]}"
180
+ elsif is_full_month?(interval)
181
+ str_result += (OSM_MONTHS[interval[:start][:month]]).to_s
182
+ elsif is_same_month?(interval)
183
+ if is_same_day?(interval)
184
+ str_result += "#{OSM_MONTHS[interval[:start][:month]]} #{interval[:start][:day] + 1 < 10 ? "0#{interval[:start][:day] + 1}" : interval[:start][:day] + 1}"
196
185
  else
197
- str_result += "#{OSM_MONTHS[interval[:start][:month]]} #{interval[:start][:day] + 1 < 10 ? "0#{interval[:start][:day] + 1}" : interval[:start][:day] + 1}-#{OSM_MONTHS[interval[:end][:month]]} #{interval[:end][:day] + 1 < 10 ? "0#{interval[:end][:day] + 1}" : interval[:end][:day] + 1}"
186
+ str_result += "#{OSM_MONTHS[interval[:start][:month]]} #{interval[:start][:day] + 1 < 10 ? "0#{interval[:start][:day] + 1}" : interval[:start][:day] + 1}-#{interval[:end][:day] + 1 < 10 ? "0#{interval[:end][:day] + 1}" : interval[:end][:day] + 1}"
198
187
  end
188
+ elsif starts_month?(interval) && ends_month?(interval)
189
+ str_result += "#{OSM_MONTHS[interval[:start][:month]]}-#{OSM_MONTHS[interval[:end][:month]]}"
190
+ else
191
+ str_result += "#{OSM_MONTHS[interval[:start][:month]]} #{interval[:start][:day] + 1 < 10 ? "0#{interval[:start][:day] + 1}" : interval[:start][:day] + 1}-#{OSM_MONTHS[interval[:end][:month]]} #{interval[:end][:day] + 1 < 10 ? "0#{interval[:end][:day] + 1}" : interval[:end][:day] + 1}"
199
192
  end
200
193
  end
201
194
  elsif selector == 'multi_year'
@@ -232,15 +225,7 @@ module OpeningHoursConverter
232
225
  str_result.strip
233
226
  end
234
227
 
235
- def end_before_start?(intervals)
236
- intervals.length == 2 &&
237
- intervals.one? { |interval| interval[:start][:day] == 0 && interval[:start][:month] == 0 } &&
238
- intervals.one? { |interval| interval[:end][:day] == 30 && interval[:end][:month] == 11 }
239
- end
240
-
241
228
  def is_only_week_interval?(r)
242
- return false if r == {}
243
-
244
229
  r.all? do |year, intervals|
245
230
  intervals.all? do |interval|
246
231
  is_week_interval?(interval)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opening_hours_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ziserman Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-10 00:00:00.000000000 Z
11
+ date: 2019-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json