Class: CLIRouter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLIRouter

Returns a new instance of CLIRouter.



5
6
7
8
# File 'lib/models/cli_router.rb', line 5

def initialize(args)
  @weather_forecast = Forecast.new(WeatherData.new)
  @args = args # in fact this is ARGV
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



3
4
5
# File 'lib/models/cli_router.rb', line 3

def args
  @args
end

#weather_forecastObject (readonly)

Returns the value of attribute weather_forecast.



3
4
5
# File 'lib/models/cli_router.rb', line 3

def weather_forecast
  @weather_forecast
end

Instance Method Details

#commandsObject



15
16
17
18
19
20
21
# File 'lib/models/cli_router.rb', line 15

def commands
  if args.length == 1
    puts weather_forecast.send(self.args[0])
  elsif args.length == 0
    help
  end
end

#helpObject



10
11
12
13
# File 'lib/models/cli_router.rb', line 10

def help
  weather_forecast.today
  puts "if you'd like a different forecast try something like 'forecast tomorrow'"
end