lib/meteo/meteo_cli.rb in meteo-1.0.2 vs lib/meteo/meteo_cli.rb in meteo-1.1.0

- old
+ new

@@ -1,34 +1,36 @@ require "thor" -require 'json' -require 'meteo' -require 'meteo/reporter' +require 'meteo/meteo' +require 'meteo/geo' +require 'meteo/weather_reporter' class MeteoCLI < Thor - include Reporter desc "quote location", "quote weather for location" long_desc <<-LONGDESC `meteo` will print weather quote for requested city. You can optionally specify a second parameter, which will print out a from message as well. > $ meteo Plainsboro, NJ > $ meteo Moscow, RU --units=metric + > $ meteo # get weather for current location based on IP address LONGDESC option :units, :aliases => "-u" + option :forecast def quote(location) + location = (location.nil? or location.strip.size == 0) ? Geo.new.quote : location + units = options[:units] ? options[:units] : "imperial" + forecast = options[:forecast] ? options[:forecast].to_i : 0 - service = Meteo.new + service = Meteo.new(forecast > 0) - response = JSON.parse(service.quote(location, units)) + response = service.quote(location, units) - if response["message"] - puts response["message"] - else - puts report(response, units).join(' ') - end + reporter = WeatherReporter.new + + reporter.report(response, units, forecast) end end