opening_hours_converter 1.13.7 → 1.13.12

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: 323387cf1e5e01948cf29e1e2a8f0037b3b70c827ac5d20e7fd68e557e87ad22
4
- data.tar.gz: 83f7ca5fa616cb1d53fe156512689540d36624b34988e79cf335f959b6dfc156
3
+ metadata.gz: 6f7598eeb7cb6738f017cf1a785eb5afddcc90717575a5a489d3c4d797579988
4
+ data.tar.gz: 7ec00410febbdb1faa8c801dc23d1ab826a5d36035a449bfcd5df96475391ae0
5
5
  SHA512:
6
- metadata.gz: d89ba9be9286a35eec8eb7b0424be359cf080e303a561241ddfe35ee68702bf48cd70f74a0bfe3c6eaa219b70f6ae27b254490a0ce1de3c61218e91c9fc0a1a5
7
- data.tar.gz: ab7e7d65a6b9bde071d9030cc3e8d7c8ffcc9cd6280c5e36d3182c0345722ef27a3d37ebc0ab67054a12effb08ae361713f85ee062232158b751ba5501f45e8d
6
+ metadata.gz: 39efeed6fd42120adb95e32505c5654bc8ddea7471d612aea2f1051856b20dcdda5bced0678374c09f9c9f9c922dab8c3b755719fba6610d84b8bb1c40c7c9c1
7
+ data.tar.gz: b5d8e74cb8320c6d97a6690a8969bc5fafebef332c14885712321c37a49265c676eec278c9727497df0695fad7f0b52afda0e1118cf8415166c27dd796864661
@@ -1,7 +1,7 @@
1
1
  module OpeningHoursConverter
2
2
  require 'date'
3
3
  require_relative './opening_hours_converter/utils'
4
- require_relative './opening_hours_converter/errors.rb'
4
+ require_relative './opening_hours_converter/errors'
5
5
  require_relative './opening_hours_converter/regex_handler'
6
6
  require_relative './opening_hours_converter/date_range'
7
7
  require_relative './opening_hours_converter/token'
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Unable to parse Opening Hours String
4
+ class OpeningHoursConverter::ParseError < StandardError; end
@@ -107,7 +107,7 @@ module OpeningHoursConverter
107
107
  elsif !(@regex_handler.month_day_regex =~ wide_range_selector).nil?
108
108
  months << get_month_day(wide_range_selector)
109
109
  elsif !(@regex_handler.month_regex =~ wide_range_selector).nil?
110
- months << get_month(wide_range_selector)
110
+ months += get_month(wide_range_selector)
111
111
  elsif !(@regex_handler.year_regex =~ wide_range_selector).nil?
112
112
  years << get_year(wide_range_selector)
113
113
  elsif !(@regex_handler.multi_month_regex =~ wide_range_selector).nil?
@@ -408,7 +408,23 @@ module OpeningHoursConverter
408
408
  else
409
409
  month_to = month_from
410
410
  end
411
- { from: month_from, to: month_to }
411
+
412
+ if month_from > month_to
413
+ [
414
+ {
415
+ from: month_from,
416
+ to: 12
417
+ },
418
+ {
419
+ from: 1,
420
+ to: month_to
421
+ }
422
+ ]
423
+ else
424
+ [
425
+ { from: month_from, to: month_to }
426
+ ]
427
+ end
412
428
  end
413
429
 
414
430
  def get_month_day(wrs)
@@ -429,6 +445,7 @@ module OpeningHoursConverter
429
445
  else
430
446
  month_to = nil
431
447
  end
448
+
432
449
  { from_day: month_from, to_day: month_to }
433
450
  end
434
451
 
@@ -500,9 +517,12 @@ module OpeningHoursConverter
500
517
 
501
518
  def get_year_multi_month_day(wrs)
502
519
  year = wrs[0...4]
503
- wrs = wrs[5..wrs.length]
504
520
 
505
- wrs.split(',').map do |wr|
521
+ wrs.split(',').map.with_index do |wr|
522
+ if wr =~ /^#{@regex_handler.year}/
523
+ year = wr[0...4]
524
+ wr = wr[5...wr.length]
525
+ end
506
526
  month = wr[0...3]
507
527
  days = wr[4...wr.length].split('-').reject { |e| e == '' }.map(&:to_i)
508
528
  if days.length == 2
@@ -531,25 +551,36 @@ module OpeningHoursConverter
531
551
  def get_multi_month(wrs)
532
552
  wrs.split(',').map do |wr|
533
553
  if wr.include?('-')
534
- start_month, end_month = wr.split('-')
554
+ start_month_day, end_month_day = wr.split('-')
555
+
556
+ start_month = start_month_day[0...3]
557
+ start_day = start_month_day[4...start_month_day.length]&.to_i
558
+
559
+ end_month = end_month_day[0...3]
560
+ end_day = end_month_day[4...end_month_day.length]&.to_i
561
+
535
562
  from = {
536
563
  month: OSM_MONTHS.find_index(start_month) + 1,
537
- day: 1
564
+ day: start_day || 1
538
565
  }
539
566
  to = {
540
567
  month: OSM_MONTHS.find_index(end_month) + 1,
541
- day: MONTH_END_DAY[OSM_MONTHS.find_index(end_month)]
568
+ day: end_day || MONTH_END_DAY[OSM_MONTHS.find_index(end_month)]
542
569
  }
543
570
  else
571
+ month = wr[0...3]
572
+ day = wr[4...wr.length]&.to_i
573
+
544
574
  from = {
545
- month: OSM_MONTHS.find_index(wr[0...3]) + 1,
546
- day: 1
575
+ month: OSM_MONTHS.find_index(month) + 1,
576
+ day: day || 1
547
577
  }
548
578
  to = {
549
- month: OSM_MONTHS.find_index(wr[0...3]) + 1,
550
- day: MONTH_END_DAY[OSM_MONTHS.find_index(wr[0...3])]
579
+ month: OSM_MONTHS.find_index(month) + 1,
580
+ day: day || MONTH_END_DAY[OSM_MONTHS.find_index(month)]
551
581
  }
552
582
  end
583
+
553
584
  { from_day: from, to_day: to }
554
585
  end
555
586
  end
@@ -163,6 +163,7 @@ module OpeningHoursConverter
163
163
  line(
164
164
  year + space +
165
165
  potential_list(
166
+ potential(year + space) +
166
167
  month +
167
168
  group(
168
169
  space, potential_range(month_day)
@@ -177,7 +178,20 @@ module OpeningHoursConverter
177
178
  end
178
179
 
179
180
  def multi_month_regex
180
- compile(line(potential_list(potential_range(month))))
181
+ compile(
182
+ line(
183
+ potential_list(
184
+ potential_range(
185
+ month +
186
+ potential(
187
+ group(
188
+ space, potential_range(month_day)
189
+ )
190
+ )
191
+ )
192
+ )
193
+ )
194
+ )
181
195
  end
182
196
 
183
197
  def week_value_regex
@@ -0,0 +1,40 @@
1
+ # Opening Hours Converter
2
+
3
+ ![](https://github.com/Publidata/opening_hours_converter/workflows/CI/badge.svg)
4
+
5
+ OpenStreetMap Opening Hours to Date & Date to Opening Hours
6
+
7
+ See [Wiki](https://wiki.openstreetmap.org/wiki/Key:opening_hours/specification) for OpenStreetMap Opening Hours specification.
8
+
9
+ # Installation
10
+
11
+ ```
12
+ gem install opening_hours_converter
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ require 'opening_hours_converter'
19
+
20
+ parsed_oh = OpeningHoursConverter::OpeningHoursParser.new.parse('Mo 10:00-12:00')
21
+ oh_string = OpeningHoursConverter::OpeningHoursBuilder.new.build(parsed_oh)
22
+ ```
23
+
24
+ ## Test
25
+
26
+ Install the dependencies with:
27
+
28
+ ```
29
+ bundle install
30
+ ```
31
+
32
+ Then run all the tests with:
33
+
34
+ ```
35
+ rspec spec --format=documentation
36
+ ```
37
+
38
+ ## Credits
39
+
40
+ Done with [YoHours](https://framagit.org/PanierAvide/YoHours) as inspiration and with constant help from the [Evaluation tool](http://openingh.openstreetmap.de/evaluation_tool/)/[repository](https://github.com/opening-hours/opening_hours.js).
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.13.7
4
+ version: 1.13.12
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-12-17 00:00:00.000000000 Z
11
+ date: 2020-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -38,8 +38,36 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Datetime range to openinghours, openinghours to datetime range. Very
42
- strongly inspired by yohours.
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Datetime range to opening hours, opening hours to datetime range. Very
70
+ strongly inspired by YoHours.
43
71
  email: tech@publidata.io
44
72
  executables: []
45
73
  extensions: []
@@ -49,6 +77,7 @@ files:
49
77
  - lib/opening_hours_converter/constants.rb
50
78
  - lib/opening_hours_converter/date_range.rb
51
79
  - lib/opening_hours_converter/day.rb
80
+ - lib/opening_hours_converter/errors.rb
52
81
  - lib/opening_hours_converter/interval.rb
53
82
  - lib/opening_hours_converter/iterator.rb
54
83
  - lib/opening_hours_converter/opening_hours_builder.rb
@@ -66,6 +95,7 @@ files:
66
95
  - lib/opening_hours_converter/week_index.rb
67
96
  - lib/opening_hours_converter/wide_interval.rb
68
97
  - lib/opening_hours_converter/year.rb
98
+ - readme.md
69
99
  homepage: https://github.com/Publidata/opening_hours_converter
70
100
  licenses:
71
101
  - AGPL-3.0
@@ -85,8 +115,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
115
  - !ruby/object:Gem::Version
86
116
  version: '0'
87
117
  requirements: []
88
- rubygems_version: 3.0.3
118
+ rubygems_version: 3.1.2
89
119
  signing_key:
90
120
  specification_version: 4
91
- summary: Datetime range to openinghours, openinghours to datetime range
121
+ summary: Datetime range to opening hours, opening hours to datetime range
92
122
  test_files: []