Class: OpeningHoursConverter::WideInterval
- Inherits:
-
Object
- Object
- OpeningHoursConverter::WideInterval
- Includes:
- Constants
- Defined in:
- lib/opening_hours_converter/wide_interval.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::PH_WEEKDAY, Constants::YEAR_DAYS_MAX
Instance Attribute Summary collapse
-
#end ⇒ Object
Returns the value of attribute end.
-
#start ⇒ Object
Returns the value of attribute start.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #always ⇒ Object
- #contains?(o) ⇒ Boolean
- #date_time(start_date, end_date = nil) ⇒ Object
- #day(start_day, start_month, start_year = nil, end_day = nil, end_month = nil, end_year = nil) ⇒ Object
- #ends_month? ⇒ Boolean
- #ends_year? ⇒ Boolean
- #equals(o) ⇒ Object
- #get_time_for_humans ⇒ Object
- #get_time_selector ⇒ Object
- #has_end_year?(date) ⇒ Boolean
- #has_inferior_end_month?(my, o) ⇒ Boolean
- #has_inferior_or_equal_end_day?(my, o) ⇒ Boolean
- #has_start_year?(date) ⇒ Boolean
- #has_superior_or_equal_start_day?(my, o) ⇒ Boolean
- #has_superior_start_month?(my, o) ⇒ Boolean
- #holiday(holiday, start_year = nil, end_year = nil) ⇒ Object
-
#initialize ⇒ WideInterval
constructor
A new instance of WideInterval.
- #is_full_month? ⇒ Boolean
- #is_full_year? ⇒ Boolean
- #month(start_month, start_year = nil, end_month = nil, end_year = nil) ⇒ Object
- #my_end_day_is_after_o_start_day?(my, o) ⇒ Boolean
- #my_end_day_is_before_o_end_day?(my, o) ⇒ Boolean
- #my_end_day_is_before_o_start_day?(my, o) ⇒ Boolean
- #my_end_is_after_o_start?(my, o) ⇒ Boolean
- #my_end_is_before_o_end?(my, o) ⇒ Boolean
- #my_start_day_is_after_o_end_day?(my, o) ⇒ Boolean
- #my_start_day_is_after_o_start_day?(my, o) ⇒ Boolean
- #my_start_day_is_before_o_end_day?(my, o) ⇒ Boolean
- #my_start_day_is_before_o_start_day?(my, o) ⇒ Boolean
- #my_start_is_after_o_start?(my, o) ⇒ Boolean
- #my_start_is_before_o_end?(my, o) ⇒ Boolean
- #my_start_is_before_o_start?(my, o) ⇒ Boolean
- #starts_month? ⇒ Boolean
- #starts_year? ⇒ Boolean
- #to_day ⇒ Object
- #touch?(o) ⇒ Boolean
- #width ⇒ Object
- #year(start_year, end_year = nil) ⇒ Object
Constructor Details
#initialize ⇒ WideInterval
Returns a new instance of WideInterval.
8 9 10 11 12 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 8 def initialize @start = nil @end = nil @type = nil end |
Instance Attribute Details
#end ⇒ Object
Returns the value of attribute end.
6 7 8 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 6 def end @end end |
#start ⇒ Object
Returns the value of attribute start.
6 7 8 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 6 def start @start end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 6 def type @type end |
Instance Method Details
#always ⇒ Object
172 173 174 175 176 177 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 172 def always @start = nil @end = nil @type = "always" self end |
#contains?(o) ⇒ Boolean
221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 221 def contains?(o) return false if o.type == "always" result = false if self.equals(o) result = false elsif @type == "always" result = true else my = to_day o = o.to_day result = has_superior_or_equal_start_day?(my, o) && has_inferior_or_equal_end_day?(my, o) end return result end |
#date_time(start_date, end_date = nil) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 118 def date_time(start_date, end_date=nil) if start_date.nil? raise(ArgumentError, "start_date is required") end if !start_date.instance_of?(DateTime) raise(ArgumentError, "start_date is not a DateTime") end if !end_date.instance_of?(DateTime) raise(ArgumentError, "end_date is not a DateTime") end @start = { day: start_date.day, month: start_date.month, year: start_date.year } if !end_date.nil? && end_date != start_date @end = { day: end_date.day, month: end_date.month, year: end_date.year } end @type = "day" self end |
#day(start_day, start_month, start_year = nil, end_day = nil, end_month = nil, end_year = nil) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 106 def day(start_day, start_month, start_year=nil, end_day=nil, end_month=nil, end_year=nil) if start_day.nil? || start_month.nil? raise(ArgumentError, "start_day, start_month and start_year are required") end @start = { day: start_day, month: start_month, year: start_year } if (!end_day.nil? && !end_month.nil? && (end_day != start_day || end_month != start_month || (!start_year.nil? && !end_year.nil? && end_year != start_year))) @end = { day: end_day, month: end_month, year: end_year } end @type = "day" self end |
#ends_month? ⇒ Boolean
195 196 197 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 195 def ends_month? @type == "month" || @type == "always" || @type == "year" || (@type == "day" && !@end.nil? && @end[:day] == MONTH_END_DAY[@end[:month] - 1]) end |
#ends_year? ⇒ Boolean
217 218 219 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 217 def ends_year? @type == "year" || @type == "always" || (@type == "day" && !@end.nil? && @end[:month] == 12 && @end[:day] == MONTH_END_DAY[@end[:month] - 1]) end |
#equals(o) ⇒ Object
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 458 def equals(o) return false unless o.instance_of?(OpeningHoursConverter::WideInterval) return @type == "always" if o.type == "always" if @type == "holiday" return (o.type == "holiday" && (@start[:year] == o.start[:year]) && (@end.nil? && o.end.nil? || (@end && o.end && @end[:year] == o.end[:year]))) end return false if @type == "always" self_to_day = to_day o_to_day = o.to_day return (self_to_day.start[:year] == o_to_day.start[:year] && self_to_day.start[:month] == o_to_day.start[:month] && self_to_day.start[:day] == o_to_day.start[:day]) && ((self_to_day.end.nil? && o_to_day.end.nil?) || ((!self_to_day.end.nil? && !o_to_day.end.nil?) && (self_to_day.end[:year] == o_to_day.end[:year] && self_to_day.end[:month] == o_to_day.end[:month] && self_to_day.end[:day] == o_to_day.end[:day]))) end |
#get_time_for_humans ⇒ Object
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 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 50 def get_time_for_humans result = "" case @type when "day" if !@end.nil? if @start[:year] && !@end[:year] || @start[:year] && @start[:year] == @end[:year] result = "du #{@start[:day]} #{IRL_MONTHS[@start[:month] - 1]} #{@start[:year]} au #{@end[:day]} #{IRL_MONTHS[@end[:month] - 1]} #{@start[:year]}" elsif @start[:year] && @end[:year] && @start[:year] != @end[:year] result = "du #{@start[:day]} #{IRL_MONTHS[@start[:month] - 1]} #{@start[:year]} au #{@end[:day]} #{IRL_MONTHS[@end[:month] - 1]} #{@end[:year]}" elsif @start[:month] != @end[:month] result = "du #{@start[:day]} #{IRL_MONTHS[@start[:month] - 1]} au #{@end[:day]} #{IRL_MONTHS[@end[:month] - 1]}" else result = "le #{@start[:day]} #{IRL_MONTHS[@start[:month] - 1]}" end else result = "le #{@start[:day]} #{IRL_MONTHS[@start[:month] - 1]} #{@start[:year] ? @start[:year] : ""}" end when "month" if !@end.nil? if @start[:year] && !@end[:year] || @start[:year] && @start[:year] == @end[:year] result = "de #{IRL_MONTHS[@start[:month] - 1]} #{@start[:year]} à #{IRL_MONTHS[@end[:month] - 1]} #{@start[:year]}" elsif @start[:year] && @end[:year] && @start[:year] != @end[:year] result = "de #{IRL_MONTHS[@start[:month] - 1]} #{@start[:year]} à #{IRL_MONTHS[@end[:month] - 1]} #{@end[:year]}" else result = "de #{IRL_MONTHS[@start[:month] - 1]} à #{IRL_MONTHS[@end[:month] - 1]}" end else result = "#{IRL_MONTHS[@start[:month] - 1]}#{@start[:year] ? " #{@start[:year]}" : ""}" end when "year" if !@end.nil? result = "de #{@start[:year]} à #{@end[:year]}" else result = "#{@start[:year]}" end when "holiday" if !@end.nil? if !@start[:year] result = "jours fériés" else result = "les jours fériés de #{@start[:year]} à #{@end[:year]}" end else if !@start[:year] result = "jours fériés" else result = "les jours fériés de #{@start[:year]}" end end when "always" result = "tout le temps" end return result end |
#get_time_selector ⇒ Object
14 15 16 17 18 19 20 21 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 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 14 def get_time_selector result = "" case @type when "day" result = "#{@start[:year].nil? ? "" : "#{@start[:year]} "}#{OSM_MONTHS[@start[:month]-1]} #{@start[:day] < 10 ? "0" : ""}#{@start[:day]}" if !@end.nil? if @start[:month] == @end[:month] result += "-#{@start[:year] == @end[:year] ? "" : "#{@end[:year]} "}#{@end[:day] < 10 ? "0" : ""}#{@end[:day]}" else result += "-#{@start[:year] == @end[:year] ? "" : "#{@end[:year]} "}#{OSM_MONTHS[@end[:month]-1]} #{@end[:day] < 10 ? "0" : ""}#{@end[:day]}" end end when "month" result = "#{@start[:year].nil? ? "" : "#{@start[:year]} "}#{OSM_MONTHS[@start[:month]-1]}" if !@end.nil? result += "-#{@start[:year] == @end[:year] ? "" : "#{@end[:year]} "}#{OSM_MONTHS[@end[:month]-1]}" end when "year" result = "#{@start[:year]}" if !@end.nil? result += "-#{@end[:year]}" end when "holiday" result = "#{@start[:year].nil? ? "" : "#{@start[:year]} "}PH" if !@end.nil? result = "#{@start[:year]}#{@start[:year] == @end[:year] ? "" : "-#{@end[:year]}"} PH" end when "always" result = "" else result = "" end result end |
#has_end_year?(date) ⇒ Boolean
454 455 456 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 454 def has_end_year?(date) !date.end[:year].nil? end |
#has_inferior_end_month?(my, o) ⇒ Boolean
439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 439 def has_inferior_end_month?(my, o) if !o.end.nil? (o.end[:month] < my.end[:month] || (o.end[:month] == my.end[:month] && o.end[:day] <= my.end[:day])) else (o.start[:month] < my.end[:month] || (o.start[:month] == my.end[:month] && o.start[:day] <= my.end[:day])) end end |
#has_inferior_or_equal_end_day?(my, o) ⇒ Boolean
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 419 def has_inferior_or_equal_end_day?(my, o) result = false return false if my.end.nil? if !o.end.nil? if has_end_year?(o) && has_end_year?(my) result = o.end[:year] < my.end[:year] || (o.end[:year] == my.end[:year] && has_inferior_end_month?(my, o)) elsif !has_end_year?(my) result = has_inferior_end_month?(my, o) end else if has_start_year?(o) && has_end_year?(my) result = o.start[:year] < my.end[:year] || (o.start[:year] == my.end[:year] && has_inferior_end_month?(my, o)) elsif !has_end_year?(my) result = has_inferior_end_month?(my, o) end end result end |
#has_start_year?(date) ⇒ Boolean
451 452 453 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 451 def has_start_year?(date) !date.start[:year].nil? end |
#has_superior_or_equal_start_day?(my, o) ⇒ Boolean
409 410 411 412 413 414 415 416 417 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 409 def has_superior_or_equal_start_day?(my, o) result = false if has_start_year?(o) && has_start_year?(my) result = o.start[:year] > my.start[:year] || (o.start[:year] == my.start[:year] && has_superior_start_month?(my, o)) elsif !has_start_year?(my) result = has_superior_start_month?(my, o) end result end |
#has_superior_start_month?(my, o) ⇒ Boolean
403 404 405 406 407 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 403 def has_superior_start_month?(my, o) (o.start[:month] > my.start[:month] || (o.start[:month] == my.start[:month] && o.start[:day] >= my.start[:day])) end |
#holiday(holiday, start_year = nil, end_year = nil) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 160 def holiday(holiday, start_year=nil, end_year=nil) if holiday.nil? || holiday != "PH" raise(ArgumentError, "holiday is required and can only be PH") end @start = { holiday: holiday, year: start_year } unless end_year.nil? || end_year == start_year @end = { holiday: holiday, year: end_year } end @type = "holiday" self end |
#is_full_month? ⇒ Boolean
179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 179 def is_full_month? return true if @type == "month" && @end.nil? return false if @end.nil? return false if !@start[:year].nil? && !@end[:year].nil? && @start[:year] != @end[:year] if @type == "day" @start[:day] == 1 && !@end.nil? && @start[:month] == @end[:month] && !@end[:day].nil? && @end[:day] == MONTH_END_DAY[@end[:month] - 1] else false end end |
#is_full_year? ⇒ Boolean
199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 199 def is_full_year? return true if @end.nil? && type == "year" return false if @end.nil? return false if !@start[:year].nil? && !@end[:year].nil? && @start[:year] != @end[:year] if @type == "month" @start[:month] == 1 && !@end.nil? && @start[:year] == @end[:year] && !@end[:month].nil? && @end[:month] == 12 elsif @type == "day" @start[:day] == 1 && @start[:month] == 1 && !@end.nil? && !@start[:year].nil? && !@end[:year].nil? && @start[:year] == @end[:year] && !@end[:month].nil? && @end[:month] == 12 && !@end[:day].nil? && @end[:day] == MONTH_END_DAY[@end[:month] - 1] else false end end |
#month(start_month, start_year = nil, end_month = nil, end_year = nil) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 136 def month(start_month, start_year=nil, end_month=nil, end_year=nil) if start_month.nil? raise(ArgumentError, "start_month is required") end @start = { month: start_month, year: start_year } if !end_month.nil? && (end_month != start_month || (!start_year.nil? && !end_year.nil? && end_year != start_year)) @end = { month: end_month, year: end_year } end @type = "month" self end |
#my_end_day_is_after_o_start_day?(my, o) ⇒ Boolean
379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 379 def my_end_day_is_after_o_start_day?(my, o) if !my.end.nil? (o.start[:month] < my.end[:month] || (o.start[:month] == my.end[:month] && o.start[:day] <= my.end[:day])) else (o.start[:month] < my.start[:month] || (o.start[:month] == my.start[:month] && o.start[:day] <= my.start[:day])) end end |
#my_end_day_is_before_o_end_day?(my, o) ⇒ Boolean
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 359 def my_end_day_is_before_o_end_day?(my, o) if !o.end.nil? && !my.end.nil? (o.end[:month] > my.end[:month] || (o.end[:month] == my.end[:month] && o.end[:day] >= my.end[:day])) elsif o.end && my.end (o.start[:month] > my.start[:month] || (o.start[:month] == my.start[:month] && o.start[:day] >= my.start[:day])) elsif o.end (o.end[:month] > my.start[:month] || (o.end[:month] == my.start[:month] && o.end[:day] >= my.start[:day])) else (o.start[:month] > my.end[:month] || (o.start[:month] == my.end[:month] && o.start[:day] >= my.end[:day])) end end |
#my_end_day_is_before_o_start_day?(my, o) ⇒ Boolean
391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 391 def my_end_day_is_before_o_start_day?(my, o) if !my.end.nil? (o.start[:month] < my.end[:month] || (o.start[:month] == my.end[:month] && o.start[:day] <= my.end[:day])) else (o.start[:month] < my.start[:month] || (o.start[:month] == my.start[:month] && o.start[:day] <= my.start[:day])) end end |
#my_end_is_after_o_start?(my, o) ⇒ Boolean
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 307 def my_end_is_after_o_start?(my, o) result = false if has_start_year?(o) && has_start_year?(my) if my.end result = o.start[:year] < my.end[:year] || (o.start[:year] == my.end[:year] && my_end_day_is_after_o_start_day?(my, o)) else result = o.start[:year] < my.start[:year] || (o.start[:year] == my.start[:year] && my_end_day_is_after_o_start_day?(my, o)) end elsif !has_start_year?(o) && !has_start_year?(my) result = my_end_day_is_after_o_start_day?(my, o) end result end |
#my_end_is_before_o_end?(my, o) ⇒ Boolean
276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 276 def my_end_is_before_o_end?(my, o) result = false if !my.end.nil? && !o.end.nil? if has_end_year?(o) && has_end_year?(my) result = o.end[:year] > my.end[:year] || (o.end[:year] == my.end[:year] && my_end_day_is_before_o_end_day?(my, o)) elsif !has_end_year?(o) && !has_end_year?(my) result = my_end_day_is_before_o_end_day?(my, o) end else my_start_is_before_o_start?(my, o) end result end |
#my_start_day_is_after_o_end_day?(my, o) ⇒ Boolean
347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 347 def my_start_day_is_after_o_end_day?(my, o) if !o.end.nil? (o.end[:month] < my.start[:month] || (o.end[:month] == my.start[:month] && o.end[:day] <= my.start[:day])) else (o.start[:month] < my.start[:month] || (o.start[:month] == my.start[:month] && o.start[:day] <= my.start[:day])) end end |
#my_start_day_is_after_o_start_day?(my, o) ⇒ Boolean
323 324 325 326 327 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 323 def my_start_day_is_after_o_start_day?(my, o) (o.start[:month] < my.start[:month] || (o.start[:month] == my.start[:month] && o.start[:day] <= my.start[:day])) end |
#my_start_day_is_before_o_end_day?(my, o) ⇒ Boolean
335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 335 def my_start_day_is_before_o_end_day?(my, o) if !o.end.nil? (o.end[:month] > my.start[:month] || (o.end[:month] == my.start[:month] && o.end[:day] >= my.start[:day])) else (o.start[:month] > my.start[:month] || (o.start[:month] == my.start[:month] && o.start[:day] >= my.start[:day])) end end |
#my_start_day_is_before_o_start_day?(my, o) ⇒ Boolean
329 330 331 332 333 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 329 def my_start_day_is_before_o_start_day?(my, o) (o.start[:month] > my.start[:month] || (o.start[:month] == my.start[:month] && o.start[:day] >= my.start[:day])) end |
#my_start_is_after_o_start?(my, o) ⇒ Boolean
254 255 256 257 258 259 260 261 262 263 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 254 def my_start_is_after_o_start?(my, o) result = false if has_start_year?(o) && has_start_year?(my) result = o.start[:year] < my.start[:year] || (o.start[:year] == my.start[:year] && my_start_day_is_after_o_start_day?(my, o)) elsif !has_start_year?(o) && !has_start_year?(my) result = my_start_day_is_after_o_start_day?(my, o) end result end |
#my_start_is_before_o_end?(my, o) ⇒ Boolean
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 291 def my_start_is_before_o_end?(my, o) result = false if has_start_year?(o) && has_start_year?(my) if o.end result = o.end[:year] > my.start[:year] || (o.end[:year] == my.start[:year] && my_start_day_is_before_o_end_day?(my, o)) else result = o.start[:year] > my.start[:year] || (o.start[:year] == my.start[:year] && my_start_day_is_before_o_end_day?(my, o)) end elsif !has_start_year?(o) && !has_start_year?(my) result = my_start_day_is_before_o_end_day?(my, o) end result end |
#my_start_is_before_o_start?(my, o) ⇒ Boolean
265 266 267 268 269 270 271 272 273 274 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 265 def my_start_is_before_o_start?(my, o) result = false if has_start_year?(o) && has_start_year?(my) result = o.start[:year] > my.start[:year] || (o.start[:year] == my.start[:year] && my_start_day_is_before_o_start_day?(my, o)) elsif !has_start_year?(o) && !has_start_year?(my) result = my_start_day_is_before_o_start_day?(my, o) end result end |
#starts_month? ⇒ Boolean
191 192 193 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 191 def starts_month? @type == "month" || @type == "always" || @type == "year" || (@type == "day" && @start[:day] == 1) end |
#starts_year? ⇒ Boolean
213 214 215 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 213 def starts_year? @type == "year" || @type == "always" || (@type == "day" && @start[:day] == 1 && @start[:month] == 1) || (@type == "month" && @start[:month] == 1) end |
#to_day ⇒ Object
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 543 def to_day case @type when "day" if @end.nil? OpeningHoursConverter::WideInterval.new.day(@start[:day], @start[:month], @start[:year]) else OpeningHoursConverter::WideInterval.new.day(@start[:day], @start[:month], @start[:year], @end[:day], @end[:month], @end[:year]) end when "month" if @end.nil? OpeningHoursConverter::WideInterval.new.day(1, @start[:month], @start[:year], MONTH_END_DAY[@start[:month] - 1], @start[:month], @start[:year]) else OpeningHoursConverter::WideInterval.new.day(1, @start[:month], @start[:year], MONTH_END_DAY[@end[:month] - 1], @end[:month], @end[:year]) end when "year" if @end.nil? OpeningHoursConverter::WideInterval.new.day(1, 1, @start[:year], 31, 12, @start[:year]) else OpeningHoursConverter::WideInterval.new.day(1, 1, @start[:year], 31, 12, @end[:year]) end end end |
#touch?(o) ⇒ Boolean
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 236 def touch?(o) return true if contains?(o) return true if o.type == "always" || @type == "always" result = false if self.equals(o) result = true else my = to_day o = o.to_day result = ((my_start_is_before_o_end?(my, o) && my_start_is_after_o_start?(my, o)) || (my_end_is_before_o_end?(my, o) && my_end_is_after_o_start?(my, o))) || ((my_start_is_before_o_end?(o, my) && my_start_is_after_o_start?(o, my)) || (my_end_is_before_o_end?(o, my) && my_end_is_after_o_start?(o, my))) end return result end |
#width ⇒ Object
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 477 def width return Float::INFINITY if @type == "always" in_day = to_day days_count = 0 if in_day.end if in_day.start[:year] && in_day.end[:year] if in_day.start[:year] != in_day.end[:year] for year in in_day.start[:year]..in_day.end[:year] if year == in_day.start[:year] for month in in_day.start[:month]..12 if month == in_day.start[:month] days_count += MONTH_END_DAY[month - 1] - in_day.start[:day] + 1 else days_count += MONTH_END_DAY[month - 1] end end elsif year == in_day.end[:year] for month in 1..in_day.end[:month] if month == in_day.end[:month] days_count += in_day.end[:day] else days_count += MONTH_END_DAY[month - 1] end end else for month in 1..12 days_count += MONTH_END_DAY[month - 1] end end end else if in_day.start[:month] == in_day.end[:month] days_count += in_day.end[:day] - in_day.start[:day] + 1 else for month in in_day.start[:month]..in_day.end[:month] if month == in_day.end[:month] days_count += in_day.end[:day] elsif month == in_day.start[:month] days_count += MONTH_END_DAY[month - 1] - in_day.start[:day] + 1 else days_count += MONTH_END_DAY[month - 1] end end end end else if in_day.start[:month] == in_day.end[:month] days_count += in_day.end[:day] - in_day.start[:day] + 1 else for month in in_day.start[:month]..in_day.end[:month] if month == in_day.end[:month] days_count += in_day.end[:day] elsif month == in_day.start[:month] days_count += MONTH_END_DAY[month - 1] - in_day.start[:day] + 1 else days_count += MONTH_END_DAY[month - 1] end end end end return days_count else return 1 end end |
#year(start_year, end_year = nil) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/opening_hours_converter/wide_interval.rb', line 148 def year(start_year, end_year=nil) if start_year.nil? raise(ArgumentError, "start_year is required") end @start = { year: start_year } unless end_year.nil? || end_year == start_year @end = { year: end_year } end @type = "year" self end |