class OpenWeatherApi::Messageable

Public Class Methods

new(options = {}) click to toggle source
# File lib/open_weather_api/messageable.rb, line 9
def initialize(options = {})
  @options = options
  @forecast = open_weather_api.new(@options).forecast
  @weather = open_weather_api.new(@options).weather
end

Public Instance Methods

forecast() click to toggle source
# File lib/open_weather_api/messageable.rb, line 15
def forecast
  @forecast
end
prevision() click to toggle source
# File lib/open_weather_api/messageable.rb, line 23
def prevision
  "#{temp_now}. #{average_weather} "
end
weather() click to toggle source
# File lib/open_weather_api/messageable.rb, line 19
def weather
  @weather
end

Private Instance Methods

average_weather() click to toggle source

FIXME: workarround to be fixed

# File lib/open_weather_api/messageable.rb, line 49
def average_weather
  message = "Média para os proximos dias: "
  5.times do |t|
    date = Date.today + 1 + t
    message += forecast.average_temperature(date).to_s
    message += temp_type
    message += " em "
    message += date.strftime("%d/%m").to_s
    message += "#{t == 4 ? '.' : ',' } "
  end
  message
end
open_weather_api() click to toggle source
# File lib/open_weather_api/messageable.rb, line 30
def open_weather_api
  ::OpenWeatherApi::OpenWeatherApi
end
temp_now() click to toggle source
# File lib/open_weather_api/messageable.rb, line 44
def temp_now
  "#{weather.main['temp'].round(1)}#{temp_type} e #{weather.weather.last['description']} em #{weather.name} em  #{forecast.convert_date(weather.dt).strftime("%d/%m")}"
end
temp_type() click to toggle source
# File lib/open_weather_api/messageable.rb, line 36
def temp_type
  case @options[:units]
    when 'metric' then 'ºC'
    when 'imperial' then 'ºF'
    else ''
  end
end