Class: TimeConverter

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

Constant Summary collapse

UTC_HOUR_OFFSET =

list of Time zones and their UTC Offset

{'HST'=>-10, 'AKST'=>-9, 'PST'=>-8,'MST'=>-7, 'CST'=>-6, 'EST'=>-5}

Instance Method Summary collapse

Constructor Details

#initialize(hours, minutes, seconds, selected_timezone) ⇒ TimeConverter

Returns a new instance of TimeConverter.



6
7
8
9
10
11
# File 'lib/utc_converter_tool.rb', line 6

def initialize hours, minutes, seconds, selected_timezone
	@hours = hours.to_i
	@minutes = minutes.to_i
	@seconds = seconds.to_i
	@selected_timezone = selected_timezone
end

Instance Method Details

#convertObject

——Conversion Methods——#



14
15
16
# File 'lib/utc_converter_tool.rb', line 14

def convert
	"#{convert_time utc_convert}:#{convert_time @minutes}:#{convert_time @seconds}"
end

#convert_time(arg) ⇒ Object



18
19
20
# File 'lib/utc_converter_tool.rb', line 18

def convert_time arg
	arg.to_s.length == 1? "0#{arg}": arg
end

#utc_convertObject

——Workhorse Converter—–#



24
25
26
27
28
29
30
31
# File 'lib/utc_converter_tool.rb', line 24

def utc_convert
	hour = @hours + UTC_HOUR_OFFSET[@selected_timezone]
	if hour.to_s[0] == "-"
		hour + 24
	else
		hour
	end
end