Class: OpeningHoursConverter::Interval

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/opening_hours_converter/interval.rb

Constant Summary

Constants included from Constants

Constants::DAYS, Constants::DAYS_MAX, Constants::EASTER_WEEKDAY, Constants::IRL_DAYS, Constants::IRL_MONTHS, Constants::MINUTES_MAX, Constants::MONTH_END_DAY, Constants::OSM_DAYS, Constants::OSM_DAYS_ABBREVIATIONS, Constants::OSM_MONTHS, Constants::PH_WEEKDAY, Constants::YEAR_DAYS_MAX

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(day_start, min_start, day_end = 0, min_end = 0, is_off = false, index = nil, is_unknown = false, open_ended = false, day_offset = 0) ⇒ Interval

is_unknown is the OSM third state ("unknown", alongside open/off) and open_ended is a time with no known closing time ("18:00+"). Both are carried purely for round-trip serialization; for interval computation is_unknown behaves like is_off (not open) and open_ended is treated as running to the end of the day.

day_offset is the OSM day offset ("easter +1 day"): the interval falls that many days after the date day_start selects.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/opening_hours_converter/interval.rb', line 16

def initialize(day_start, min_start, day_end = 0, min_end = 0, is_off = false, index = nil, is_unknown = false, open_ended = false, day_offset = 0)
  @day_start = day_start
  @day_end = day_end
  @start = min_start
  @end = min_end
  @is_off = is_off
  # The weekday index is an OSM nth_entry list ("Sa[1,3]"), so it is always
  # held as an array; a lone index is wrapped rather than special-cased.
  @index = index.nil? ? nil : Array(index)
  @is_unknown = is_unknown
  @open_ended = open_ended
  @day_offset = day_offset || 0

  if @day_end == 0 && @end == 0
    @day_end = DAYS_MAX
    @end = MINUTES_MAX
  end
end

Instance Attribute Details

#day_endObject (readonly)

Returns the value of attribute day_end.



6
7
8
# File 'lib/opening_hours_converter/interval.rb', line 6

def day_end
  @day_end
end

#day_offsetObject (readonly)

Returns the value of attribute day_offset.



6
7
8
# File 'lib/opening_hours_converter/interval.rb', line 6

def day_offset
  @day_offset
end

#day_startObject (readonly)

Returns the value of attribute day_start.



6
7
8
# File 'lib/opening_hours_converter/interval.rb', line 6

def day_start
  @day_start
end

#endObject (readonly)

Returns the value of attribute end.



6
7
8
# File 'lib/opening_hours_converter/interval.rb', line 6

def end
  @end
end

#indexObject (readonly)

Returns the value of attribute index.



6
7
8
# File 'lib/opening_hours_converter/interval.rb', line 6

def index
  @index
end

#is_offObject (readonly)

Returns the value of attribute is_off.



6
7
8
# File 'lib/opening_hours_converter/interval.rb', line 6

def is_off
  @is_off
end

#is_unknownObject (readonly)

Returns the value of attribute is_unknown.



6
7
8
# File 'lib/opening_hours_converter/interval.rb', line 6

def is_unknown
  @is_unknown
end

#open_endedObject (readonly)

Returns the value of attribute open_ended.



6
7
8
# File 'lib/opening_hours_converter/interval.rb', line 6

def open_ended
  @open_ended
end

#startObject (readonly)

Returns the value of attribute start.



6
7
8
# File 'lib/opening_hours_converter/interval.rb', line 6

def start
  @start
end

Instance Method Details

#max?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/opening_hours_converter/interval.rb', line 39

def max?
  @day_end == DAYS_MAX && @end == MINUTES_MAX
end

#single_day?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/opening_hours_converter/interval.rb', line 35

def single_day?
  @day_start == @day_end
end

#single_day_end_at_midnight?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/opening_hours_converter/interval.rb', line 43

def single_day_end_at_midnight?
  @day_end == @day_start + 1 && @end == 0
end