class OpeningHoursConverter::RegexHandler

Public Instance Methods

comma() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 248
def comma
  ',' + space + '?'
end
comment() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 302
def comment
  '\"[^\"]*\"'
end
comment_regex() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 201
def comment_regex
  compile(line(comment))
end
compile(string) click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 318
def compile(string)
  @compile ||= {}
  @compile[string] ||= Regexp.compile(string)
end
day_regex() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 114
def day_regex
  compile(
    line(
      potential_range(month_day)
    )
  )
end
end_of_line() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 310
def end_of_line
  '$'
end
escape(string) click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 323
def escape(string)
  @escape ||= {}
  @escape[string] ||= Regexp.escape(string)
end
full_time() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 217
def full_time
  '24/7'
end
group(*args) click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 209
def group(*args)
  "(#{args.join})"
end
holiday_regex() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 58
def holiday_regex
  compile(line(ph))
end
int_range(max) click to toggle source
# 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) click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 314
def line(pattern)
  start_of_line + pattern + end_of_line
end
modifier() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 278
def modifier
  'off'
end
month() click to toggle source
# 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() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 290
def month_day
  group('[012]?[0-9]|3[01]')
end
month_day_regex() click to toggle source
# 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() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 54
def month_regex
  compile(line(potential_range(month)))
end
multi_month_regex() click to toggle source
# 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() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 282
def ph
  'PH'
end
potential(pattern) click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 232
def potential(pattern)
  group(pattern) + '?'
end
potential_comma() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 252
def potential_comma
  ',? ?'
end
potential_list(pattern, optional_pattern = pattern) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 5
def rule_modifier_regex
  /^(open|closed|off)$/i
end
space() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 256
def space
  ' '
end
start_of_line() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 306
def start_of_line
  '^'
end
time() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 213
def time
  group(int_range(24)) + ':' + group(int_range(59))
end
time_regex() click to toggle source
# 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() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 274
def week
  'week'
end
week_day() click to toggle source
# 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() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 244
def week_day_modifier
  '\\[' + group('[1-5]|\\-1') + '\\]'
end
week_day_or_holiday_regex() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 9
def week_key_regex
  compile(line(week))
end
week_modifier() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 264
def week_modifier
  '\/[1-9]'
end
week_number() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 260
def week_number
  group('[01234]?[0-9]|5[0123]')
end
week_regex() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 298
def year
  '\\d{4}'
end
year_month_day_regex() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/opening_hours_converter/regex_handler.rb, line 106
def year_regex
  compile(
    line(
      potential_range(year)
    )
  )
end
year_week_regex() click to toggle source
# 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() click to toggle source
# 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