Class: OpeningHoursConverter::OpeningHoursTime

Inherits:
Object
  • Object
show all
Defined in:
lib/opening_hours_converter/opening_hours_time.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(minute_start = nil, minute_end = nil) ⇒ OpeningHoursTime

Returns a new instance of OpeningHoursTime.



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

def initialize(minute_start = nil, minute_end = nil)
  @start = minute_start
  @end = minute_end unless minute_start == minute_end
end

Instance Attribute Details

#endObject (readonly)

Returns the value of attribute end.



3
4
5
# File 'lib/opening_hours_converter/opening_hours_time.rb', line 3

def end
  @end
end

#priorityObject (readonly)

Returns the value of attribute priority.



3
4
5
# File 'lib/opening_hours_converter/opening_hours_time.rb', line 3

def priority
  @priority
end

#startObject (readonly)

Returns the value of attribute start.



3
4
5
# File 'lib/opening_hours_converter/opening_hours_time.rb', line 3

def start
  @start
end

Instance Method Details

#equals(t) ⇒ Object



15
16
17
# File 'lib/opening_hours_converter/opening_hours_time.rb', line 15

def equals(t)
  @start == t.start && @end == t.end
end

#getObject



10
11
12
13
# File 'lib/opening_hours_converter/opening_hours_time.rb', line 10

def get
  return 'off' if @start.nil? && @end.nil?
  "#{time_string(@start)}#{@end.nil? ? '' : "-#{time_string(@end)}"}"
end

#time_string(minutes) ⇒ Object



19
20
21
22
23
24
# File 'lib/opening_hours_converter/opening_hours_time.rb', line 19

def time_string(minutes)
  fminutes = minutes.to_f
  h = (fminutes / 60).floor.to_i
  m = (fminutes % 60).to_i
  "#{h < 10 ? '0' : ''}#{h}:#{m < 10 ? '0' : ''}#{m}"
end