opening_hours_converter 1.12.1 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e14bfa479d2bea81a625afc37b44c032f2ecfbea62218002592f0efb79d25c3
|
4
|
+
data.tar.gz: 301201253cf8495de144f0509a49052733b7cd55a2583e994088c179b5e57260
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 007507ee2cb8438b64e5fb8d6e142680ed2b99eb979a64f1b6b69f8e16f6053140cf4b9b07522b8d2dae8cbc557428d85e3a37e786d29bf6687f70c1c03b4871
|
7
|
+
data.tar.gz: cf8467a7b1623b9884ba530c8df2a58bcabbb78c1bef48e1e95dc1801c47191c64723ed75685b3377f9f0045d934f66264d232207c45bbffc275b87f4892d9f4
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module OpeningHoursConverter
|
2
2
|
require 'date'
|
3
3
|
require_relative './opening_hours_converter/utils'
|
4
|
+
require_relative './opening_hours_converter/regex_handler'
|
4
5
|
require_relative './opening_hours_converter/date_range'
|
5
6
|
require_relative './opening_hours_converter/token'
|
6
7
|
require_relative './opening_hours_converter/tokenizer'
|
@@ -8,29 +8,7 @@ module OpeningHoursConverter
|
|
8
8
|
include Utils
|
9
9
|
|
10
10
|
def initialize
|
11
|
-
@
|
12
|
-
@RGX_WEEK_KEY = /^week$/
|
13
|
-
@RGX_WEEK = /^week ([01234]?[0-9]|5[0123])(\-([01234]?[0-9]|5[0123]))?(, ?([01234]?[0-9]|5[0123])(\-([01234]?[0-9]|5[0123]))?)*$/
|
14
|
-
@RGX_WEEK_VAL = /^([01234]?[0-9]|5[0123])(\-([01234]?[0-9]|5[0123]))?(, ?([01234]?[0-9]|5[0123])(\-([01234]?[0-9]|5[0123]))?)*$/
|
15
|
-
@RGX_WEEK_WITH_MODIFIER = /^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])?)?)*$/
|
16
|
-
@RGX_WEEK_VAL_WITH_MODIFIER = /^([01234]?[0-9]|5[0123])(\-([01234]?[0-9]|5[0123])(\/[1-9])?)?(, ?([01234]?[0-9]|5[0123])(\-([01234]?[0-9]|5[0123])(\/[1-9])?)?)*$/
|
17
|
-
@RGX_MONTH = /^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))?\:?$/
|
18
|
-
@RGX_MONTHDAY = /^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([012]?[0-9]|3[01])(\-((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) )?([012]?[0-9]|3[01]))?\:?$/
|
19
|
-
@RGX_TIME = /^((([01]?[0-9]|2[01234])\:[012345][0-9](\-([01]?[0-9]|2[01234])\:[012345][0-9])?(,([01]?[0-9]|2[01234])\:[012345][0-9](\-([01]?[0-9]|2[01234])\:[012345][0-9])?)*)|(24\/7))$/
|
20
|
-
@RGX_WEEKDAY = /^(((Mo|Tu|We|Th|Fr|Sa|Su)(\-(Mo|Tu|We|Th|Fr|Sa|Su))?)|(PH))(,(((Mo|Tu|We|Th|Fr|Sa|Su)(\-(Mo|Tu|We|Th|Fr|Sa|Su))?)|(PH)))*$/
|
21
|
-
@RGX_HOLIDAY = /^(PH|SH|easter)$/
|
22
|
-
@RGX_WD = /^(Mo|Tu|We|Th|Fr|Sa|Su)(\-(Mo|Tu|We|Th|Fr|Sa|Su))?$/
|
23
|
-
@RGX_WD_WITH_MODIFIER = /^(Mo|Tu|We|Th|Fr|Sa|Su)\[([1-5]|\-1)\]$/
|
24
|
-
@RGX_DAY = /^([012]?[0-9]|3[01])(\-[012]?[0-9]|3[01])?$/
|
25
|
-
@RGX_YEAR = /^(\d{4})(\-(\d{4}))?$/
|
26
|
-
@RGX_YEAR_PH = /^(\d{4})( PH|(\-(\d{4}) PH))\:?$/
|
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
|
-
@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
|
-
@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])(-([012]?[0-9]|3[01]))?)?,? ?)*?$/
|
31
|
-
@RGX_YEAR_MULTI_MONTH = /^(\d{4}) ((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec),? ?)*?$/
|
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)))?\:?$/
|
33
|
-
@RGX_COMMENT = /^\"[^\"]*\"$/
|
11
|
+
@regex_handler = RegexHandler.new
|
34
12
|
end
|
35
13
|
|
36
14
|
def parse(oh)
|
@@ -121,28 +99,30 @@ module OpeningHoursConverter
|
|
121
99
|
end
|
122
100
|
if !wide_range_selector.empty?
|
123
101
|
wide_range_selector = wide_range_selector.strip
|
124
|
-
|
125
|
-
if !(@
|
102
|
+
|
103
|
+
if !(@regex_handler.year_month_day_regex =~ wide_range_selector).nil?
|
126
104
|
years << get_year_month_day(wide_range_selector)
|
127
|
-
elsif !(@
|
105
|
+
elsif !(@regex_handler.year_month_regex =~ wide_range_selector).nil?
|
128
106
|
years << get_year_month(wide_range_selector)
|
129
|
-
elsif !(@
|
107
|
+
elsif !(@regex_handler.month_day_regex =~ wide_range_selector).nil?
|
130
108
|
months << get_month_day(wide_range_selector)
|
131
|
-
elsif !(@
|
109
|
+
elsif !(@regex_handler.month_regex =~ wide_range_selector).nil?
|
132
110
|
months << get_month(wide_range_selector)
|
133
|
-
elsif !(@
|
111
|
+
elsif !(@regex_handler.year_regex =~ wide_range_selector).nil?
|
134
112
|
years << get_year(wide_range_selector)
|
135
|
-
elsif !(@
|
113
|
+
elsif !(@regex_handler.multi_month_regex =~ wide_range_selector).nil?
|
114
|
+
months += get_multi_month(wide_range_selector)
|
115
|
+
elsif !(@regex_handler.year_multi_month_regex =~ wide_range_selector).nil?
|
136
116
|
months += get_year_multi_month(wide_range_selector)
|
137
|
-
elsif !(@
|
117
|
+
elsif !(@regex_handler.year_multi_month_day_regex =~ wide_range_selector).nil?
|
138
118
|
months += get_year_multi_month_day(wide_range_selector)
|
139
|
-
elsif !(@
|
119
|
+
elsif !(@regex_handler.year_week_with_modifier_regex =~ wide_range_selector).nil?
|
140
120
|
weeks << get_year_week_with_modifier(wide_range_selector)
|
141
|
-
elsif !(@
|
121
|
+
elsif !(@regex_handler.year_week_regex =~ wide_range_selector).nil?
|
142
122
|
weeks << get_year_week(wide_range_selector)
|
143
|
-
elsif !(@
|
123
|
+
elsif !(@regex_handler.week_with_modifier_regex =~ wide_range_selector).nil?
|
144
124
|
weeks << get_week_with_modifier(wide_range_selector)
|
145
|
-
elsif !(@
|
125
|
+
elsif !(@regex_handler.week_regex =~ wide_range_selector).nil?
|
146
126
|
weeks << get_week(wide_range_selector)
|
147
127
|
else
|
148
128
|
raise ArgumentError, "Unsupported selector #{wide_range_selector}"
|
@@ -548,21 +528,61 @@ module OpeningHoursConverter
|
|
548
528
|
end
|
549
529
|
end
|
550
530
|
|
531
|
+
def get_multi_month(wrs)
|
532
|
+
wrs.split(',').map do |wr|
|
533
|
+
if wr.include?('-')
|
534
|
+
start_month, end_month = wr.split('-')
|
535
|
+
from = {
|
536
|
+
month: OSM_MONTHS.find_index(start_month) + 1,
|
537
|
+
day: 1
|
538
|
+
}
|
539
|
+
to = {
|
540
|
+
month: OSM_MONTHS.find_index(end_month) + 1,
|
541
|
+
day: MONTH_END_DAY[OSM_MONTHS.find_index(end_month)]
|
542
|
+
}
|
543
|
+
else
|
544
|
+
from = {
|
545
|
+
month: OSM_MONTHS.find_index(wr[0...3]) + 1,
|
546
|
+
day: 1
|
547
|
+
}
|
548
|
+
to = {
|
549
|
+
month: OSM_MONTHS.find_index(wr[0...3]) + 1,
|
550
|
+
day: MONTH_END_DAY[OSM_MONTHS.find_index(wr[0...3])]
|
551
|
+
}
|
552
|
+
end
|
553
|
+
{ from_day: from, to_day: to }
|
554
|
+
end
|
555
|
+
end
|
556
|
+
|
551
557
|
def get_year_multi_month(wrs)
|
552
558
|
year = wrs[0...4]
|
553
559
|
wrs = wrs[5..wrs.length]
|
554
560
|
|
555
561
|
wrs.split(',').map do |wr|
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
562
|
+
if wr.include?('-')
|
563
|
+
start_month, end_month = wr.split('-')
|
564
|
+
from = {
|
565
|
+
year: year.to_i,
|
566
|
+
month: OSM_MONTHS.find_index(start_month) + 1,
|
567
|
+
day: 1
|
568
|
+
}
|
569
|
+
to = {
|
570
|
+
year: year.to_i,
|
571
|
+
month: OSM_MONTHS.find_index(end_month) + 1,
|
572
|
+
day: MONTH_END_DAY[OSM_MONTHS.find_index(end_month)]
|
573
|
+
}
|
574
|
+
else
|
575
|
+
from = {
|
576
|
+
year: year.to_i,
|
577
|
+
month: OSM_MONTHS.find_index(wr[0...3]) + 1,
|
578
|
+
day: 1
|
579
|
+
}
|
580
|
+
to = {
|
581
|
+
year: year.to_i,
|
582
|
+
month: OSM_MONTHS.find_index(wr[0...3]) + 1,
|
583
|
+
day: MONTH_END_DAY[OSM_MONTHS.find_index(wr[0...3])]
|
584
|
+
}
|
585
|
+
end
|
566
586
|
{ from_day: from, to_day: to }
|
567
587
|
end
|
568
588
|
end
|
@@ -597,9 +617,9 @@ module OpeningHoursConverter
|
|
597
617
|
weekday_selector = weekday_selector.split(',')
|
598
618
|
|
599
619
|
weekday_selector.each do |wd|
|
600
|
-
if !(@
|
620
|
+
if !(@regex_handler.holiday_regex =~ wd).nil?
|
601
621
|
weekdays << { from: -2, to: -2, index: nil }
|
602
|
-
elsif !(@
|
622
|
+
elsif !(@regex_handler.week_day_regex =~ wd).nil?
|
603
623
|
single_weekday = wd.split('-')
|
604
624
|
|
605
625
|
wd_from = OSM_DAYS.find_index(single_weekday[0])
|
@@ -610,7 +630,7 @@ module OpeningHoursConverter
|
|
610
630
|
end
|
611
631
|
|
612
632
|
weekdays << { from: wd_from, to: wd_to, index: nil }
|
613
|
-
elsif !(@
|
633
|
+
elsif !(@regex_handler.week_day_with_modifier_regex =~ wd).nil?
|
614
634
|
|
615
635
|
from, to = wd[0...wd.index('[')].split('-')
|
616
636
|
index = wd[wd.index('[') + 1...wd.index(']')]
|
@@ -783,10 +803,10 @@ module OpeningHoursConverter
|
|
783
803
|
def is_part_of_wide_interval?(string)
|
784
804
|
is_wide_interval = false
|
785
805
|
string.split('-').each do |str|
|
786
|
-
if (!(@
|
787
|
-
!(@
|
788
|
-
!(@
|
789
|
-
((@
|
806
|
+
if (!(@regex_handler.year_regex =~ str).nil? || !(@regex_handler.year_month_regex =~ str).nil? || !(@regex_handler.year_month_day_regex =~ str).nil? ||
|
807
|
+
!(@regex_handler.month_day_regex =~ str).nil? || !(@regex_handler.month_day_regex =~ str).nil? || !(@regex_handler.month_regex =~ str).nil? ||
|
808
|
+
!(@regex_handler.week_key_regex =~ str).nil? || !(@regex_handler.week_value_regex =~ str).nil? || !(@regex_handler.week_value_with_modifier_regex =~ str).nil?) &&
|
809
|
+
((@regex_handler.time_regex =~ str).nil? && (@regex_handler.week_day_or_holiday_regex =~ str).nil?)
|
790
810
|
is_wide_interval = true
|
791
811
|
else
|
792
812
|
return false
|
@@ -796,58 +816,58 @@ module OpeningHoursConverter
|
|
796
816
|
end
|
797
817
|
|
798
818
|
def is_comment?(token)
|
799
|
-
!(@
|
819
|
+
!(@regex_handler.comment_regex =~ token).nil?
|
800
820
|
end
|
801
821
|
|
802
822
|
def is_holiday?(token)
|
803
|
-
!(@
|
823
|
+
!(@regex_handler.holiday_regex =~ token).nil?
|
804
824
|
end
|
805
825
|
|
806
826
|
def is_rule_modifier?(token)
|
807
|
-
!(@
|
827
|
+
!(@regex_handler.rule_modifier_regex =~ token).nil?
|
808
828
|
end
|
809
829
|
|
810
830
|
def is_time?(token)
|
811
|
-
!(@
|
831
|
+
!(@regex_handler.time_regex =~ token).nil?
|
812
832
|
end
|
813
833
|
|
814
834
|
def is_weekday?(token)
|
815
|
-
!(@
|
835
|
+
!(@regex_handler.week_day_or_holiday_regex =~ token).nil?
|
816
836
|
end
|
817
837
|
|
818
838
|
def is_weekday_with_modifier?(token)
|
819
|
-
!(@
|
839
|
+
!(@regex_handler.week_day_with_modifier_regex =~ token).nil?
|
820
840
|
end
|
821
841
|
|
822
842
|
def is_year?(token)
|
823
|
-
!(@
|
843
|
+
!(@regex_handler.year_regex =~ token).nil?
|
824
844
|
end
|
825
845
|
|
826
846
|
def is_week_key?(token)
|
827
|
-
!(@
|
847
|
+
!(@regex_handler.week_key_regex =~ token).nil?
|
828
848
|
end
|
829
849
|
|
830
850
|
def is_week_val?(token)
|
831
|
-
!(@
|
851
|
+
!(@regex_handler.week_value_regex =~ token).nil?
|
832
852
|
end
|
833
853
|
|
834
854
|
def is_week_with_modifier?(token)
|
835
|
-
!(@
|
855
|
+
!(@regex_handler.week_with_modifier_regex =~ token).nil?
|
836
856
|
end
|
837
857
|
|
838
858
|
def is_week_val_with_modifier?(token)
|
839
|
-
!(@
|
859
|
+
!(@regex_handler.week_value_with_modifier_regex =~ token).nil?
|
840
860
|
end
|
841
861
|
|
842
862
|
def is_year_week?(token)
|
843
|
-
!(@
|
863
|
+
!(@regex_handler.year_week_regex =~ token).nil?
|
844
864
|
end
|
845
865
|
|
846
866
|
def is_year_week_with_modifier?(token)
|
847
|
-
!(@
|
867
|
+
!(@regex_handler.year_week_with_modifier_regex =~ token).nil?
|
848
868
|
end
|
849
869
|
def is_year_multi_month_day?(token)
|
850
|
-
!(@
|
870
|
+
!(@regex_handler.year_multi_month_day_regex =~ token).nil?
|
851
871
|
end
|
852
872
|
end
|
853
873
|
end
|
@@ -0,0 +1,314 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpeningHoursConverter
|
4
|
+
class RegexHandler
|
5
|
+
def rule_modifier_regex
|
6
|
+
/^(open|closed|off)$/i
|
7
|
+
end
|
8
|
+
|
9
|
+
def week_key_regex
|
10
|
+
compile(line(week))
|
11
|
+
end
|
12
|
+
|
13
|
+
def week_regex
|
14
|
+
compile(
|
15
|
+
line(
|
16
|
+
week + space + potential_list(
|
17
|
+
potential_range(int_range(53))
|
18
|
+
)
|
19
|
+
)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def week_with_modifier_regex
|
24
|
+
compile(
|
25
|
+
line(
|
26
|
+
week + space + potential_list(
|
27
|
+
potential_range(int_range(53), group(int_range(53) + potential(week_modifier)))
|
28
|
+
)
|
29
|
+
)
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def week_value_with_modifier_regex
|
34
|
+
compile(
|
35
|
+
line(
|
36
|
+
potential_list(
|
37
|
+
potential_range(int_range(53), group(int_range(53) + potential(week_modifier)))
|
38
|
+
)
|
39
|
+
)
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
def month_day_regex
|
44
|
+
compile(
|
45
|
+
line(
|
46
|
+
potential_range(
|
47
|
+
month + space + month_day,
|
48
|
+
potential(month + space) + month_day
|
49
|
+
)
|
50
|
+
)
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def month_regex
|
55
|
+
compile(line(potential_range(month)))
|
56
|
+
end
|
57
|
+
|
58
|
+
def holiday_regex
|
59
|
+
compile(line(ph))
|
60
|
+
end
|
61
|
+
|
62
|
+
def time_regex
|
63
|
+
compile(
|
64
|
+
line(
|
65
|
+
potential_list(
|
66
|
+
group(
|
67
|
+
potential_range(
|
68
|
+
group(time)
|
69
|
+
) + '|' + group(full_time)
|
70
|
+
)
|
71
|
+
)
|
72
|
+
)
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def week_day_or_holiday_regex
|
77
|
+
compile(
|
78
|
+
line(
|
79
|
+
potential_list(
|
80
|
+
group(
|
81
|
+
potential_range(
|
82
|
+
group(week_day)
|
83
|
+
) + '|' + group(ph)
|
84
|
+
)
|
85
|
+
)
|
86
|
+
)
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
def week_day_regex
|
91
|
+
compile(
|
92
|
+
line(
|
93
|
+
potential_range(week_day)
|
94
|
+
)
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
def week_day_with_modifier_regex
|
99
|
+
compile(
|
100
|
+
line(
|
101
|
+
week_day + week_day_modifier
|
102
|
+
)
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
def year_regex
|
107
|
+
compile(
|
108
|
+
line(
|
109
|
+
potential_range(year)
|
110
|
+
)
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
def day_regex
|
115
|
+
compile(
|
116
|
+
line(
|
117
|
+
potential_range(month_day)
|
118
|
+
)
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
def year_ph_regex
|
123
|
+
compile(
|
124
|
+
line(
|
125
|
+
year + group(space + ph + '|' + '-' + year + space + ph)
|
126
|
+
)
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
def year_week_regex
|
131
|
+
compile(
|
132
|
+
line(
|
133
|
+
potential_range(year) + space + week + space +
|
134
|
+
group(
|
135
|
+
potential_list(potential_range(week_number))
|
136
|
+
)
|
137
|
+
)
|
138
|
+
)
|
139
|
+
end
|
140
|
+
|
141
|
+
def year_week_with_modifier_regex
|
142
|
+
compile(
|
143
|
+
line(
|
144
|
+
potential_range(year) + space + week + space +
|
145
|
+
potential_list(week_with_modifier)
|
146
|
+
)
|
147
|
+
)
|
148
|
+
end
|
149
|
+
|
150
|
+
def year_month_day_regex
|
151
|
+
compile(
|
152
|
+
line(
|
153
|
+
potential_range(
|
154
|
+
year + space + month + space + month_day,
|
155
|
+
potential(year + space) + potential(month + space) + month_day
|
156
|
+
)
|
157
|
+
)
|
158
|
+
)
|
159
|
+
end
|
160
|
+
|
161
|
+
def year_multi_month_day_regex
|
162
|
+
compile(
|
163
|
+
line(
|
164
|
+
year + space +
|
165
|
+
potential_list(
|
166
|
+
month +
|
167
|
+
group(
|
168
|
+
space, potential_range(month_day)
|
169
|
+
)
|
170
|
+
)
|
171
|
+
)
|
172
|
+
)
|
173
|
+
end
|
174
|
+
|
175
|
+
def year_multi_month_regex
|
176
|
+
compile(line(year + space + group(potential_range(month), potential_comma) + '*'))
|
177
|
+
end
|
178
|
+
|
179
|
+
def multi_month_regex
|
180
|
+
compile(line(potential_list(potential_range(month))))
|
181
|
+
end
|
182
|
+
|
183
|
+
def week_value_regex
|
184
|
+
compile(line(potential_list(potential_range(int_range(53)))))
|
185
|
+
end
|
186
|
+
|
187
|
+
def comment_regex
|
188
|
+
compile(line(comment))
|
189
|
+
end
|
190
|
+
|
191
|
+
def year_month_regex
|
192
|
+
compile(line(potential_range(year + space + month, potential(year + space) + month)))
|
193
|
+
end
|
194
|
+
|
195
|
+
def group(*args)
|
196
|
+
"(#{args.join})"
|
197
|
+
end
|
198
|
+
|
199
|
+
def time
|
200
|
+
group(int_range(24)) + ':' + group(int_range(59))
|
201
|
+
end
|
202
|
+
|
203
|
+
def full_time
|
204
|
+
'24/7'
|
205
|
+
end
|
206
|
+
|
207
|
+
def int_range(max)
|
208
|
+
raise 'too high' if max > 99
|
209
|
+
|
210
|
+
base = max / 10
|
211
|
+
|
212
|
+
unit_max = max - base * 10
|
213
|
+
base_ten = "[0-#{base - 1}]?"
|
214
|
+
base_unit = '[0-9]'
|
215
|
+
group(group("#{base_ten}#{base_unit}") + '|' + group("#{base}[0-#{unit_max}]"))
|
216
|
+
end
|
217
|
+
|
218
|
+
def potential(pattern)
|
219
|
+
group(pattern) + '?'
|
220
|
+
end
|
221
|
+
|
222
|
+
def potential_range(pattern, optional_pattern = pattern)
|
223
|
+
group(pattern, group('-', optional_pattern), '?')
|
224
|
+
end
|
225
|
+
|
226
|
+
def potential_list(pattern, optional_pattern = pattern)
|
227
|
+
group(pattern, group(group(comma, optional_pattern), '?'), '*')
|
228
|
+
end
|
229
|
+
|
230
|
+
def week_day_modifier
|
231
|
+
'\\[' + group('[1-5]|\\-1') + '\\]'
|
232
|
+
end
|
233
|
+
|
234
|
+
def comma
|
235
|
+
',' + space + '?'
|
236
|
+
end
|
237
|
+
|
238
|
+
def potential_comma
|
239
|
+
',? ?'
|
240
|
+
end
|
241
|
+
|
242
|
+
def space
|
243
|
+
' '
|
244
|
+
end
|
245
|
+
|
246
|
+
def week_number
|
247
|
+
group('[01234]?[0-9]|5[0123]')
|
248
|
+
end
|
249
|
+
|
250
|
+
def week_modifier
|
251
|
+
'\/[1-9]'
|
252
|
+
end
|
253
|
+
|
254
|
+
def week_with_modifier
|
255
|
+
group(
|
256
|
+
potential_range(week_number, week_number + potential(week_modifier))
|
257
|
+
)
|
258
|
+
end
|
259
|
+
|
260
|
+
def week
|
261
|
+
'week'
|
262
|
+
end
|
263
|
+
|
264
|
+
def modifier
|
265
|
+
'off'
|
266
|
+
end
|
267
|
+
|
268
|
+
def ph
|
269
|
+
'PH'
|
270
|
+
end
|
271
|
+
|
272
|
+
def week_day
|
273
|
+
group('Mo|Tu|We|Th|Fr|Sa|Su')
|
274
|
+
end
|
275
|
+
|
276
|
+
def month_day
|
277
|
+
group('[012]?[0-9]|3[01]')
|
278
|
+
end
|
279
|
+
|
280
|
+
def month
|
281
|
+
group('Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec')
|
282
|
+
end
|
283
|
+
|
284
|
+
def year
|
285
|
+
'\\d{4}'
|
286
|
+
end
|
287
|
+
|
288
|
+
def comment
|
289
|
+
'\"[^\"]*\"'
|
290
|
+
end
|
291
|
+
|
292
|
+
def start_of_line
|
293
|
+
'^'
|
294
|
+
end
|
295
|
+
|
296
|
+
def end_of_line
|
297
|
+
'$'
|
298
|
+
end
|
299
|
+
|
300
|
+
def line(pattern)
|
301
|
+
start_of_line + pattern + end_of_line
|
302
|
+
end
|
303
|
+
|
304
|
+
def compile(string)
|
305
|
+
@compile ||= {}
|
306
|
+
@compile[string] ||= Regexp.compile(string)
|
307
|
+
end
|
308
|
+
|
309
|
+
def escape(string)
|
310
|
+
@escape ||= {}
|
311
|
+
@escape[string] ||= Regexp.escape(string)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
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.
|
4
|
+
version: 1.13.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-10-
|
11
|
+
date: 2019-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/opening_hours_converter/opening_hours_rule.rb
|
58
58
|
- lib/opening_hours_converter/opening_hours_time.rb
|
59
59
|
- lib/opening_hours_converter/public_holiday.rb
|
60
|
+
- lib/opening_hours_converter/regex_handler.rb
|
60
61
|
- lib/opening_hours_converter/token.rb
|
61
62
|
- lib/opening_hours_converter/tokenizer.rb
|
62
63
|
- lib/opening_hours_converter/tokens_handler.rb
|