Class: Weather
- Inherits:
-
Object
- Object
- Weather
- Includes:
- Cinch::Plugin
- Defined in:
- lib/rateless_bot/plugins/weather.rb
Instance Method Summary collapse
- #execute(m) ⇒ Object
- #help ⇒ Object
-
#initialize(*args) ⇒ Weather
constructor
A new instance of Weather.
- #make_current_weather_str(current_weather) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Weather
Returns a new instance of Weather.
12 13 14 15 |
# File 'lib/rateless_bot/plugins/weather.rb', line 12 def initialize(*args) super = { units: 'metric', APPID: config[:api_key] } end |
Instance Method Details
#execute(m) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/rateless_bot/plugins/weather.rb', line 19 def execute(m) city = m..split('!weather ')[1] current_weather = OpenWeather::Current.city(city, ) m.reply make_current_weather_str(current_weather) end |
#help ⇒ Object
6 7 8 |
# File 'lib/rateless_bot/plugins/weather.rb', line 6 def help '!weather CITY/ZIP - gets the current temperature for a given city/zip' end |
#make_current_weather_str(current_weather) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rateless_bot/plugins/weather.rb', line 27 def make_current_weather_str(current_weather) if current_weather['cod'] == '404' return 'Error: City not found' elsif current_weather['cod'] != 200 # number is not a string; report bug return "Error: response code #{current_weather['cod']}" end city = current_weather['name'] country = ISO3166::Country.new(current_weather['sys']['country']).name humidity = current_weather['main']['humidity'] temp_celsius = current_weather['main']['temp'].round(1) temp_fahrenheit = (temp_celsius * 1.8 + 32).round(1) weather_description = current_weather['weather'][0]['description'] s = "Weather for #{city} (#{country}): " s += "#{temp_celsius}°C (#{temp_fahrenheit}°F); #{humidity}% humidity; " s += "#{weather_description}" end |