Module: TimeZoneConverter

Defined in:
lib/time_zone_converter.rb,
lib/time_zone_converter/cli.rb,
lib/time_zone_converter/version.rb,
lib/time_zone_converter/json_data_transformer.rb

Defined Under Namespace

Classes: Cli, Error, JsonDataTransformer

Constant Summary collapse

VERSION =
"0.2.5"

Class Method Summary collapse

Class Method Details

.call(args, time, method = :utc) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/time_zone_converter.rb', line 15

def self.call(args, time, method = :utc)
  arr = Array.new

  if method == :utc
    time = string_to_time(time, "UTC")
    arr = args.map { |city| [city, get_time(city, time)] }
  else # :local
    # Get time with zone for the first city
    time_zone = get_nearest_time_zone(args.first)

    if time.nil?
      time = Time.current.in_time_zone(time_zone)
    else
      time = string_to_time(time, time_zone)
    end

    # Add first item
    arr << [args.first, time]

    # Convert time for the rest of the cities in the args
    args[1..-1].each { |city| arr << [city, get_time(city, time)] }
    arr
  end
end