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
9
10
# File 'lib/opening_hours_converter/opening_hours_time.rb', line 5

def initialize(minute_start=nil, minute_end=nil)
  @start = minute_start
  unless minute_start == minute_end
    @end = minute_end
  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



17
18
19
# File 'lib/opening_hours_converter/opening_hours_time.rb', line 17

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

#getObject



12
13
14
15
# File 'lib/opening_hours_converter/opening_hours_time.rb', line 12

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

#time_string(minutes) ⇒ Object



21
22
23
24
25
26
# File 'lib/opening_hours_converter/opening_hours_time.rb', line 21

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