class SimpleOpenWeatherMap::Report

Attributes

city_id[RW]
config[RW]

Public Class Methods

new(config) click to toggle source
# File lib/simple_open_weather_map/report.rb, line 5
def initialize(config)
  if config.is_a?(Hash) then
    @config = SimpleOpenWeatherMap::Config.new(config)
  elsif config.is_a?(SimpleOpenWeatherMap::Config) then
    @config = config
  else
    raise "config should be Hash or SimpleOpenWeatherMap::Config object."
  end
end

Public Instance Methods

current() click to toggle source
# File lib/simple_open_weather_map/report.rb, line 17
def current
    weather.current(@config)
end
forecast() click to toggle source
# File lib/simple_open_weather_map/report.rb, line 21
def forecast
    weather.forecast(@config)
end
puts_report() click to toggle source
# File lib/simple_open_weather_map/report.rb, line 25
def puts_report
  puts format_current(current)
  puts ""

  cnt = 0
  forecast["list"].each do |data|
    if cnt != 0 then
      puts format_forecast(data)
    end

    cnt += 1
  end
end

Private Instance Methods

format_current(data) click to toggle source
# File lib/simple_open_weather_map/report.rb, line 45
def format_current(data)
  # temp main, description :name
  "%d°C %s, %s :%s" % [
      data["main"]["temp"],
      data["weather"][0]["main"],
      data["weather"][0]["description"],
      data["name"]
  ]
end
format_forecast(data) click to toggle source
# File lib/simple_open_weather_map/report.rb, line 55
def format_forecast(data)
  # day temp-min - temp.max description
  "%-4s\t\t%2d°C - %2d°C\t\t%s" % [
      ::Time.at(data["dt"]).strftime("%a"),
      data["temp"]["min"],
      data["temp"]["max"],
      data["weather"][0]["description"]
  ]
end
weather() click to toggle source
# File lib/simple_open_weather_map/report.rb, line 41
def weather
    @weather = @weather || SimpleOpenWeatherMap::Weather.new
end