Class: OpeningHoursConverter::RegexHandler
- Inherits:
-
Object
- Object
- OpeningHoursConverter::RegexHandler
- Defined in:
- lib/opening_hours_converter/regex_handler.rb
Instance Method Summary collapse
- #comma ⇒ Object
- #comment ⇒ Object
- #comment_regex ⇒ Object
- #compile(string) ⇒ Object
- #day_regex ⇒ Object
- #end_of_line ⇒ Object
- #escape(string) ⇒ Object
- #full_time ⇒ Object
- #group(*args) ⇒ Object
- #holiday_regex ⇒ Object
- #int_range(max) ⇒ Object
- #line(pattern) ⇒ Object
- #modifier ⇒ Object
- #month ⇒ Object
- #month_day ⇒ Object
- #month_day_regex ⇒ Object
- #month_regex ⇒ Object
- #multi_month_regex ⇒ Object
- #ph ⇒ Object
- #potential(pattern) ⇒ Object
- #potential_comma ⇒ Object
- #potential_list(pattern, optional_pattern = pattern) ⇒ Object
- #potential_range(pattern, optional_pattern = pattern) ⇒ Object
- #rule_modifier_regex ⇒ Object
- #space ⇒ Object
- #start_of_line ⇒ Object
- #time ⇒ Object
- #time_regex ⇒ Object
- #week ⇒ Object
- #week_day ⇒ Object
- #week_day_modifier ⇒ Object
- #week_day_or_holiday_regex ⇒ Object
- #week_day_regex ⇒ Object
- #week_day_with_modifier_regex ⇒ Object
- #week_key_regex ⇒ Object
- #week_modifier ⇒ Object
- #week_number ⇒ Object
- #week_regex ⇒ Object
- #week_value_regex ⇒ Object
- #week_value_with_modifier_regex ⇒ Object
- #week_with_modifier ⇒ Object
- #week_with_modifier_regex ⇒ Object
- #year ⇒ Object
- #year_month_day_regex ⇒ Object
- #year_month_regex ⇒ Object
- #year_multi_month_day_regex ⇒ Object
- #year_multi_month_regex ⇒ Object
- #year_ph_regex ⇒ Object
- #year_regex ⇒ Object
- #year_week_regex ⇒ Object
- #year_week_with_modifier_regex ⇒ Object
Instance Method Details
#comma ⇒ Object
248 249 250 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 248 def comma ',' + space + '?' end |
#comment ⇒ Object
302 303 304 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 302 def comment '\"[^\"]*\"' end |
#comment_regex ⇒ Object
201 202 203 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 201 def comment_regex compile(line(comment)) end |
#compile(string) ⇒ Object
318 319 320 321 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 318 def compile(string) @compile ||= {} @compile[string] ||= Regexp.compile(string, Regexp::IGNORECASE) end |
#day_regex ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 114 def day_regex compile( line( potential_range(month_day) ) ) end |
#end_of_line ⇒ Object
310 311 312 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 310 def end_of_line '$' end |
#escape(string) ⇒ Object
323 324 325 326 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 323 def escape(string) @escape ||= {} @escape[string] ||= Regexp.escape(string) end |
#full_time ⇒ Object
217 218 219 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 217 def full_time '24/7' end |
#group(*args) ⇒ Object
209 210 211 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 209 def group(*args) "(#{args.join})" end |
#holiday_regex ⇒ Object
58 59 60 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 58 def holiday_regex compile(line(ph)) end |
#int_range(max) ⇒ Object
221 222 223 224 225 226 227 228 229 230 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 221 def int_range(max) raise ArgumentError, 'too high' if max > 99 base = max / 10 unit_max = max - base * 10 base_ten = "[0-#{base - 1}]?" base_unit = '[0-9]' group(group("#{base_ten}#{base_unit}") + '|' + group("#{base}[0-#{unit_max}]")) end |
#line(pattern) ⇒ Object
314 315 316 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 314 def line(pattern) start_of_line + pattern + end_of_line end |
#modifier ⇒ Object
278 279 280 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 278 def modifier 'off' end |
#month ⇒ Object
294 295 296 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 294 def month group('Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec') end |
#month_day ⇒ Object
290 291 292 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 290 def month_day group('[012]?[0-9]|3[01]') end |
#month_day_regex ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 43 def month_day_regex compile( line( potential_range( month + space + month_day, potential(month + space) + month_day ) ) ) end |
#month_regex ⇒ Object
54 55 56 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 54 def month_regex compile(line(potential_range(month))) end |
#multi_month_regex ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 180 def multi_month_regex compile( line( potential_list( potential_range( month + potential( group( space, potential_range(month_day) ) ) ) ) ) ) end |
#ph ⇒ Object
282 283 284 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 282 def ph 'PH' end |
#potential(pattern) ⇒ Object
232 233 234 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 232 def potential(pattern) group(pattern) + '?' end |
#potential_comma ⇒ Object
252 253 254 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 252 def potential_comma ',? ?' end |
#potential_list(pattern, optional_pattern = pattern) ⇒ Object
240 241 242 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 240 def potential_list(pattern, optional_pattern = pattern) group(pattern, group(group(comma, optional_pattern), '?'), '*') end |
#potential_range(pattern, optional_pattern = pattern) ⇒ Object
236 237 238 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 236 def potential_range(pattern, optional_pattern = pattern) group(pattern, group('-', optional_pattern), '?') end |
#rule_modifier_regex ⇒ Object
5 6 7 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 5 def rule_modifier_regex /^(open|closed|off)$/i end |
#space ⇒ Object
256 257 258 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 256 def space ' ' end |
#start_of_line ⇒ Object
306 307 308 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 306 def start_of_line '^' end |
#time ⇒ Object
213 214 215 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 213 def time group(int_range(24)) + ':' + group(int_range(59)) end |
#time_regex ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 62 def time_regex compile( line( potential_list( group( potential_range( group(time) ) + '|' + group(full_time) ) ) ) ) end |
#week ⇒ Object
274 275 276 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 274 def week 'week' end |
#week_day ⇒ Object
286 287 288 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 286 def week_day group('Mo|Tu|We|Th|Fr|Sa|Su') end |
#week_day_modifier ⇒ Object
244 245 246 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 244 def week_day_modifier '\\[' + group('[1-5]|\\-1') + '\\]' end |
#week_day_or_holiday_regex ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 76 def week_day_or_holiday_regex compile( line( potential_list( group( potential_range( group(week_day) ) + '|' + group(ph) ) ) ) ) end |
#week_day_regex ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 90 def week_day_regex compile( line( potential_range(week_day) ) ) end |
#week_day_with_modifier_regex ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 98 def week_day_with_modifier_regex compile( line( week_day + week_day_modifier ) ) end |
#week_key_regex ⇒ Object
9 10 11 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 9 def week_key_regex compile(line(week)) end |
#week_modifier ⇒ Object
264 265 266 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 264 def week_modifier '\/[1-9]' end |
#week_number ⇒ Object
260 261 262 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 260 def week_number group('[01234]?[0-9]|5[0123]') end |
#week_regex ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 13 def week_regex compile( line( week + space + potential_list( potential_range(int_range(53)) ) ) ) end |
#week_value_regex ⇒ Object
197 198 199 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 197 def week_value_regex compile(line(potential_list(potential_range(int_range(53))))) end |
#week_value_with_modifier_regex ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 33 def week_value_with_modifier_regex compile( line( potential_list( potential_range(int_range(53), group(int_range(53) + potential(week_modifier))) ) ) ) end |
#week_with_modifier ⇒ Object
268 269 270 271 272 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 268 def week_with_modifier group( potential_range(week_number, week_number + potential(week_modifier)) ) end |
#week_with_modifier_regex ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 23 def week_with_modifier_regex compile( line( week + space + potential_list( potential_range(int_range(53), group(int_range(53) + potential(week_modifier))) ) ) ) end |
#year ⇒ Object
298 299 300 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 298 def year '\\d{4}' end |
#year_month_day_regex ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 150 def year_month_day_regex compile( line( potential_range( year + space + month + space + month_day, potential(year + space) + potential(month + space) + month_day ) ) ) end |
#year_month_regex ⇒ Object
205 206 207 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 205 def year_month_regex compile(line(potential_range(year + space + month, potential(year + space) + month))) end |
#year_multi_month_day_regex ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 161 def year_multi_month_day_regex compile( line( year + space + potential_list( potential(year + space) + month + group( space, potential_range(month_day) ) ) ) ) end |
#year_multi_month_regex ⇒ Object
176 177 178 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 176 def year_multi_month_regex compile(line(year + space + group(potential_range(month), potential_comma) + '*')) end |
#year_ph_regex ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 122 def year_ph_regex compile( line( year + group(space + ph + '|' + '-' + year + space + ph) ) ) end |
#year_regex ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 106 def year_regex compile( line( potential_range(year) ) ) end |
#year_week_regex ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 130 def year_week_regex compile( line( potential_range(year) + space + week + space + group( potential_list(potential_range(week_number)) ) ) ) end |
#year_week_with_modifier_regex ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/opening_hours_converter/regex_handler.rb', line 141 def year_week_with_modifier_regex compile( line( potential_range(year) + space + week + space + potential_list(week_with_modifier) ) ) end |