Class: OpeningHoursConverter::OpeningHoursParser
- Inherits:
-
Object
- Object
- OpeningHoursConverter::OpeningHoursParser
- Includes:
- Constants
- Defined in:
- lib/opening_hours_converter/opening_hours_parser.rb
Constant Summary
Constants included from Constants
Constants::DAYS, Constants::DAYS_MAX, Constants::IRL_DAYS, Constants::IRL_MONTHS, Constants::MINUTES_MAX, Constants::MONTH_END_DAY, Constants::OSM_DAYS, Constants::OSM_MONTHS, Constants::YEAR_DAYS_MAX
Instance Attribute Summary collapse
-
#RGX_HOLIDAY ⇒ Object
Returns the value of attribute RGX_HOLIDAY.
-
#RGX_MONTH ⇒ Object
Returns the value of attribute RGX_MONTH.
-
#RGX_MONTHDAY ⇒ Object
Returns the value of attribute RGX_MONTHDAY.
-
#RGX_RULE_MODIFIER ⇒ Object
Returns the value of attribute RGX_RULE_MODIFIER.
-
#RGX_TIME ⇒ Object
Returns the value of attribute RGX_TIME.
-
#RGX_WD ⇒ Object
Returns the value of attribute RGX_WD.
-
#RGX_WEEK_KEY ⇒ Object
Returns the value of attribute RGX_WEEK_KEY.
-
#RGX_WEEK_VAL ⇒ Object
Returns the value of attribute RGX_WEEK_VAL.
-
#RGX_WEEKDAY ⇒ Object
Returns the value of attribute RGX_WEEKDAY.
Instance Method Summary collapse
- #add_interval(typical, weekdays, times) ⇒ Object
- #add_interval_wd(typical, times, wd) ⇒ Object
- #as_minutes(time) ⇒ Object
- #get_month(wrs) ⇒ Object
- #get_month_day(wrs) ⇒ Object
- #get_times(time_selector) ⇒ Object
- #get_weekdays(weekday_selector) ⇒ Object
- #get_year(wrs) ⇒ Object
- #get_year_month(wrs) ⇒ Object
- #get_year_month_day(wrs) ⇒ Object
-
#initialize ⇒ OpeningHoursParser
constructor
A new instance of OpeningHoursParser.
- #is_rule_modifier?(token) ⇒ Boolean
- #is_time?(token) ⇒ Boolean
- #is_weekday?(token) ⇒ Boolean
- #is_year?(token) ⇒ Boolean
- #parse(oh) ⇒ Object
- #remove_interval(typical, weekdays, times) ⇒ Object
- #remove_interval_wd(typical, times, wd) ⇒ Object
- #tokenize(block) ⇒ Object
Constructor Details
#initialize ⇒ OpeningHoursParser
Returns a new instance of OpeningHoursParser.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 7 def initialize @RGX_RULE_MODIFIER = /^(open|closed|off)$/i @RGX_WEEK_KEY = /^week$/ @RGX_WEEK_VAL = /^([01234]?[0-9]|5[0123])(\-([01234]?[0-9]|5[0123]))?(,([01234]?[0-9]|5[0123])(\-([01234]?[0-9]|5[0123]))?)*\:?$/ @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))?\:?$/ @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]))?\:?$/ @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))$/ @RGX_WEEKDAY = /^(((Mo|Tu|We|Th|Fr|Sa|Su)(\-(Mo|Tu|We|Th|Fr|Sa|Su))?)|(PH|SH|easter))(,(((Mo|Tu|We|Th|Fr|Sa|Su)(\-(Mo|Tu|We|Th|Fr|Sa|Su))?)|(PH|SH|easter)))*$/ @RGX_HOLIDAY = /^(PH|SH|easter)$/ @RGX_WD = /^(Mo|Tu|We|Th|Fr|Sa|Su)(\-(Mo|Tu|We|Th|Fr|Sa|Su))?$/ @RGX_YEAR = /^(\d{4})(\-(\d{4}))?$/ @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]))?\:?$/ @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)))?\:?$/ end |
Instance Attribute Details
#RGX_HOLIDAY ⇒ Object
Returns the value of attribute RGX_HOLIDAY.
6 7 8 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 6 def RGX_HOLIDAY @RGX_HOLIDAY end |
#RGX_MONTH ⇒ Object
Returns the value of attribute RGX_MONTH.
6 7 8 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 6 def RGX_MONTH @RGX_MONTH end |
#RGX_MONTHDAY ⇒ Object
Returns the value of attribute RGX_MONTHDAY.
6 7 8 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 6 def RGX_MONTHDAY @RGX_MONTHDAY end |
#RGX_RULE_MODIFIER ⇒ Object
Returns the value of attribute RGX_RULE_MODIFIER.
6 7 8 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 6 def RGX_RULE_MODIFIER @RGX_RULE_MODIFIER end |
#RGX_TIME ⇒ Object
Returns the value of attribute RGX_TIME.
6 7 8 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 6 def RGX_TIME @RGX_TIME end |
#RGX_WD ⇒ Object
Returns the value of attribute RGX_WD.
6 7 8 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 6 def RGX_WD @RGX_WD end |
#RGX_WEEK_KEY ⇒ Object
Returns the value of attribute RGX_WEEK_KEY.
6 7 8 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 6 def RGX_WEEK_KEY @RGX_WEEK_KEY end |
#RGX_WEEK_VAL ⇒ Object
Returns the value of attribute RGX_WEEK_VAL.
6 7 8 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 6 def RGX_WEEK_VAL @RGX_WEEK_VAL end |
#RGX_WEEKDAY ⇒ Object
Returns the value of attribute RGX_WEEKDAY.
6 7 8 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 6 def RGX_WEEKDAY @RGX_WEEKDAY end |
Instance Method Details
#add_interval(typical, weekdays, times) ⇒ Object
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 457 def add_interval(typical, weekdays, times) if typical.instance_of?(OpeningHoursConverter::Day) if weekdays[:from] != 0 || (weekdays[:to] !=0 && times[:from] <= times[:to]) weekdays = weekdays.dup weekdays[:from] = 0 if times[:from] <= times[:to] weekdays[:to] = 0 else weekdays[:to] = 1 end end end if weekdays[:from] <= weekdays[:to] for wd in weekdays[:from]..weekdays[:to] add_interval_wd(typical, times, wd) end else for wd in weekdays[:from]..6 add_interval_wd(typical, times, wd) end for wd in 0..weekdays[:to] add_interval_wd(typical, times, wd) end end end |
#add_interval_wd(typical, times, wd) ⇒ Object
484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 484 def add_interval_wd(typical, times, wd) if times[:to] >= times[:from] typical.add_interval(OpeningHoursConverter::Interval.new(wd, times[:from], wd, times[:to])) else if wd < 6 typical.add_interval(OpeningHoursConverter::Interval.new(wd, times[:from], wd+1, times[:to])) else typical.add_interval(OpeningHoursConverter::Interval.new(wd, times[:from], wd+1, 24*60)) typical.add_interval(OpeningHoursConverter::Interval.new(0, 0, 0, times[:to])) end end end |
#as_minutes(time) ⇒ Object
501 502 503 504 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 501 def as_minutes(time) values = time.split(':') values[0].to_i * 60 + values[1].to_i end |
#get_month(wrs) ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 285 def get_month(wrs) single_month = wrs.gsub(/\:$/, '').split('-') month_from = OSM_MONTHS.find_index(single_month[0]) + 1 if month_from < 1 raise ArgumentError, "Invalid month : #{single_month[0]}" end if single_month.length > 1 month_to = OSM_MONTHS.find_index(single_month[1]) + 1 if month_to < 1 raise ArgumentError, "Invalid month : #{single_month[1]}" end else month_to = month_from end { from: month_from, to: month_to } end |
#get_month_day(wrs) ⇒ Object
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 303 def get_month_day(wrs) single_month = wrs.gsub(/\:$/, '').split('-') month_from = single_month[0].split(' ') month_from = { day: month_from[1].to_i, month: OSM_MONTHS.find_index(month_from[0]) + 1 } if month_from[:month] < 1 raise ArgumentError, "Invalid month : #{month_from.inspect}" end if single_month.length > 1 month_to = single_month[1].split(' ') month_to = { day: month_to[1].to_i, month: OSM_MONTHS.find_index(month_to[0]) + 1 } if month_to[:month] < 1 raise ArgumentError, "Invalid month : #{month_to.inspect}" end else month_to = nil end { from_day: month_from, to_day: month_to } end |
#get_times(time_selector) ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 381 def get_times(time_selector) times = [] from = nil to = nil if time_selector == "24/7" times << {from: 0, to: 24*60} else time_selector = time_selector.split(',') time_selector.each do |ts| single_time = ts.split('-') from = as_minutes(single_time[0]) if single_time.length > 1 to = as_minutes(single_time[1]) else to = from end times << {from: from, to: to} end end times end |
#get_weekdays(weekday_selector) ⇒ Object
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 403 def get_weekdays(weekday_selector) weekdays = [] wd_from = nil wd_to = nil weekday_selector = weekday_selector.split(',') weekday_selector.each do |wd| if !(@RGX_HOLIDAY =~ wd).nil? elsif !(@RGX_WD =~ wd).nil? single_weekday = wd.split('-') wd_from = OSM_DAYS.find_index(single_weekday[0]) if single_weekday.length > 1 wd_to = OSM_DAYS.find_index(single_weekday[1]) else wd_to = wd_from end weekdays << {from: wd_from, to: wd_to} else raise ArgumentError, "Invalid weekday interval : #{wd}" end end weekdays end |
#get_year(wrs) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 267 def get_year(wrs) single_year = wrs.gsub(/\:$/, '').split('-') year_from = single_year[0].to_i if year_from < 1 raise ArgumentError, "Invalid year : #{single_year[0]}" end if single_year.length > 1 year_to = single_year[1].to_i if year_to < 1 raise ArgumentError, "Invalid year : #{single_year[1]}" end else year_to = nil end { from: year_from, to: year_to } end |
#get_year_month(wrs) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 324 def get_year_month(wrs) single_year_month = wrs.gsub(/\:$/, '').split('-') year_month_from = single_year_month[0].split(' ') year_month_from = { month: OSM_MONTHS.find_index(year_month_from[1]) + 1, year: year_month_from[0].to_i } if year_month_from.length < 1 raise ArgumentError, "Invalid year_month : #{year_month_from.inspect}" end if single_year_month.length > 1 year_month_to = single_year_month[1].split(' ') if year_month_to.length == 2 year_month_to = { month: OSM_MONTHS.find_index(year_month_to[1]) + 1, year: year_month_to[0].to_i } elsif year_month_to.length == 1 year_month_to = { month: OSM_MONTHS.find_index(year_month_to[1]) + 1, year: year_month_from[:year] } end if year_month_to.length < 1 raise ArgumentError, "Invalid year_month : #{year_month_to.inspect}" end else year_month_to = nil end { from_month: year_month_from, to_month: year_month_to } end |
#get_year_month_day(wrs) ⇒ Object
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 347 def get_year_month_day(wrs) single_year_month_day = wrs.gsub(/\:$/, '').split('-') year_month_day_from = single_year_month_day[0].split(' ') year_month_day_from = { day: year_month_day_from[2].to_i, month: OSM_MONTHS.find_index(year_month_day_from[1]) + 1, year: year_month_day_from[0].to_i } if year_month_day_from.length < 1 raise ArgumentError, "Invalid year_month_day : #{year_month_day_from.inspect}" end if single_year_month_day.length > 1 year_month_day_to = single_year_month_day[1].split(' ') if year_month_day_to.length == 3 year_month_day_to = { day: year_month_day_to[2].to_i, month: OSM_MONTHS.find_index(year_month_day_to[1]) + 1, year: year_month_day_to[0].to_i } elsif year_month_day_to.length == 2 year_month_day_to = { day: year_month_day_to[1].to_i, month: OSM_MONTHS.find_index(year_month_day_to[0]) + 1, year: year_month_day_from[:year] } elsif year_month_day_to.length == 1 year_month_day_to = { day: year_month_day_to[0].to_i, month: year_month_day_from[:month], year: year_month_day_from[:year] } end if year_month_day_to.length < 1 raise ArgumentError, "Invalid year_month_day : #{year_month_day_to.inspect}" end else year_month_day_to = nil end { from_day: year_month_day_from, to_day: year_month_day_to } end |
#is_rule_modifier?(token) ⇒ Boolean
506 507 508 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 506 def is_rule_modifier?(token) !(@RGX_RULE_MODIFIER =~ token).nil? end |
#is_time?(token) ⇒ Boolean
509 510 511 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 509 def is_time?(token) !(@RGX_TIME =~ token).nil? end |
#is_weekday?(token) ⇒ Boolean
512 513 514 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 512 def is_weekday?(token) !(@RGX_WEEKDAY =~ token).nil? end |
#is_year?(token) ⇒ Boolean
515 516 517 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 515 def is_year?(token) !(@RGX_YEAR =~ token).nil? end |
#parse(oh) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 22 def parse(oh) result = [] blocks = oh.split(';') rule_modifier = nil time_selector = nil weekday_selector = nil wide_range_selector = nil month_selector = nil times = nil weekdays = nil weeks = nil months = nil years = nil single_month = nil month_from = nil month_to = nil single_year = nil year_from = nil year_to = nil single_year = nil year_from = nil year_to = nil date_ranges = nil date_range = nil dr_obj = nil res_dr_id = nil blocks.each do |block| block.strip! next if block.length == 0 tokens = tokenize(block) current_token = tokens.length - 1 # get state if current_token >= 0 && is_rule_modifier?(tokens[current_token]) rule_modifier = tokens[current_token].downcase current_token -= 1 end times = [] if current_token >= 0 && is_time?(tokens[current_token]) time_selector = tokens[current_token] times = get_times(time_selector) current_token -= 1 end # get weekdays selector weekdays = [] if time_selector == "24/7" weekdays << {from: 0, to: 6} elsif current_token >= 0 && is_weekday?(tokens[current_token]) weekday_selector = tokens[current_token] weekdays = get_weekdays(weekday_selector) current_token -= 1 end # years = [] # if current_token >= 0 && is_year?(tokens[current_token]) # year_selector = tokens[current_token] # year_selector = year_selector.split(',') # year_selector.each do |y| # single_year = y.gsub(/\:$/, '').split('-') # year_from = single_year[0] # if single_year.length > 1 # year_to = single_year[1] # else # year_to = year_from # end # years << {from: year_from, to: year_to} # end # current_token -= 1 # end months = [] years = [] if current_token >= 0 wide_range_selector = tokens[0] for i in 1..current_token wide_range_selector += " #{tokens[i]}" end if wide_range_selector.length > 0 wide_range_selector = wide_range_selector.strip wide_range_selector = wide_range_selector.split(',') wide_range_selector.each do |wrs| if !(@RGX_YEAR_MONTH_DAY =~ wrs).nil? years << get_year_month_day(wrs) elsif !(@RGX_YEAR_MONTH =~ wrs).nil? years << get_year_month(wrs) elsif !(@RGX_MONTHDAY =~ wrs).nil? months << get_month_day(wrs) elsif !(@RGX_MONTH =~ wrs).nil? months << get_month(wrs) elsif !(@RGX_YEAR =~ wrs).nil? years << {from: year_from, to: year_to} else raise ArgumentError, "Unsupported selector #{wrs}" end end end end if current_token == tokens.length - 1 raise ArgumentError, "Unreadable string" end puts "months : #{months}" puts "weekdays : #{weekdays}" puts "times : #{times}" puts "years : #{years}" puts "rule_modifier : #{rule_modifier}" date_ranges = [] if months.length > 0 months.each do |month| if !month[:from_day].nil? if !month[:to_day].nil? date_range = OpeningHoursConverter::WideInterval.new.day(month[:from_day][:day], month[:from_day][:month], nil, month[:to_day][:day], month[:to_day][:month], nil) else date_range = OpeningHoursConverter::WideInterval.new.day(month[:from_day][:day], month[:from_day][:month]) end date_ranges << date_range else if !month[:to].nil? date_range = OpeningHoursConverter::WideInterval.new.month(month[:from], nil, month[:to]) else date_range = OpeningHoursConverter::WideInterval.new.month(month[:from]) end date_ranges << date_range end end elsif years.length > 0 years.each do |year| # binding.pry if !year[:to].nil? if !year[:from_day].nil? date_range = OpeningHoursConverter::WideInterval.new.day(year[:from_day][:day], year[:from_day][:month], year[:from_day][:year], year[:to_day][:day], year[:to_day][:month], year[:to_day][:year]) elsif !year[:from_month].nil? date_range = OpeningHoursConverter::WideInterval.new.month(year[:from_month][:month], year[:from_month][:year], year[:to_month][:month], year[:to_month][:year]) else date_range = OpeningHoursConverter::WideInterval.new.year(year[:from], year[:to]) end else if !year[:from_month].nil? date_range = OpeningHoursConverter::WideInterval.new.month(year[:from_month][:month], year[:from_month][:year]) elsif !year[:from_day].nil? date_range = OpeningHoursConverter::WideInterval.new.day(year[:from_day][:day], year[:from_day][:month], year[:from_day][:year]) else date_range = OpeningHoursConverter::WideInterval.new.year(year[:from]) end end date_ranges << date_range end else date_ranges << OpeningHoursConverter::WideInterval.new.always end if weekdays.length == 0 weekdays << {from: 0, to: OSM_DAYS.length - 1} end if times.length == 0 times << {from: 0, to: 24*60} end # pasur date_ranges.each do |dr| found_date_range = false res_dr_id = 0 while res_dr_id < result.length && !found_date_range if result[res_dr_id].wide_interval.equals(dr) found_date_range = true else res_dr_id += 1 end end if found_date_range dr_obj = result[res_dr_id] else dr_obj = OpeningHoursConverter::DateRange.new(dr) general = -1 for res_dr_id in 0...result.length if result[res_dr_id].is_general_for?(OpeningHoursConverter::DateRange.new(dr)) general = res_dr_id end end if general >= 0 dr_obj.typical.copy_intervals(result[general].typical.intervals) end result << dr_obj end for wd_id in 0...weekdays.length if weekdays[wd_id][:from] <= weekdays[wd_id][:to] for wd_rm in weekdays[wd_id][:from]..weekdays[wd_id][:to] if dr_obj.defines_typical_week? dr_obj.typical.remove_intervals_during_day(wd_rm) else dr_obj.typical.clear_intervals end end else for wd_rm in weekdays[wd_id][:from]..6 if dr_obj.defines_typical_week? dr_obj.typical.remove_intervals_during_day(wd_rm) else dr_obj.typical.clear_intervals end end for wd_rm in 0..weekdays[wd_id][:to] if dr_obj.defines_typical_week? dr_obj.typical.remove_intervals_during_day(wd_rm) else dr_obj.typical.clear_intervals end end end for t_id in 0...times.length if rule_modifier == "closed" || rule_modifier == "off" remove_interval(dr_obj.typical, weekdays[wd_id], times[t_id]) else add_interval(dr_obj.typical, weekdays[wd_id], times[t_id]) end end end end end return result end |
#remove_interval(typical, weekdays, times) ⇒ Object
429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 429 def remove_interval(typical, weekdays, times) if weekdays[:from] <= weekdays[:to] for wd in weekdays[:from]..weekdays[:to] typical.remove_intervals_during_day(wd) end else for wd in weekdays[:from]..6 typical.remove_intervals_during_day(wd) end for wd in 0..weekdays[:from] typical.remove_intervals_during_day(wd) end end end |
#remove_interval_wd(typical, times, wd) ⇒ Object
444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 444 def remove_interval_wd(typical, times, wd) if times[:to] >= times[:from] typical.remove_interval(OpeningHoursConverter::Interval.new(wd, times[:from], wd, times[:to])) else if wd < 6 typical.remove_interval(OpeningHoursConverter::Interval.new(wd, times[:from], wd+1, times[:to])) else typical.remove_interval(OpeningHoursConverter::Interval.new(wd, times[:from], wd+1, 24*60)) typical.remove_interval(OpeningHoursConverter::Interval.new(0, 0, 0, times[:to])) end end end |
#tokenize(block) ⇒ Object
497 498 499 |
# File 'lib/opening_hours_converter/opening_hours_parser.rb', line 497 def tokenize(block) block.split(' ') end |