From c0617afa4ce165c363b37a1ec1a14bad705b92d9 Mon Sep 17 00:00:00 2001 From: Andrew Kreps Date: Fri, 20 Nov 2015 10:42:48 -0800 Subject: [PATCH] cloud max % --- lib/lita/handlers/forecasts.rb | 8 +++++++- spec/lita/handlers/forecast_io_spec.rb | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/lita/handlers/forecasts.rb b/lib/lita/handlers/forecasts.rb index bc2a8b8..0b165c5 100644 --- a/lib/lita/handlers/forecasts.rb +++ b/lib/lita/handlers/forecasts.rb @@ -191,9 +191,15 @@ def do_the_cloud_thing(forecast, chars) # O ◎ ] data = forecast['hourly']['data'].slice(0,23) + max = 0 + data.each do |datum| + if datum['cloudCover'] > max + max = datum['cloudCover'] + end + end str = get_dot_str(chars, data, 0, 1, 'cloudCover') - "24h cloud cover |#{str}|" + "24h cloud cover |#{str}| max #{max * 100}%" end def do_the_sunrise_thing(forecast) diff --git a/spec/lita/handlers/forecast_io_spec.rb b/spec/lita/handlers/forecast_io_spec.rb index 406f52f..492ca5e 100644 --- a/spec/lita/handlers/forecast_io_spec.rb +++ b/spec/lita/handlers/forecast_io_spec.rb @@ -187,7 +187,7 @@ it '!ansicloud' do send_message 'ansicloud' - expect(replies.last).to eq('Portland, OR 24h cloud cover |___________▁▁▁▁▁▁▁▁▃▅▅▅|') + expect(replies.last).to eq('Portland, OR 24h cloud cover |___________▁▁▁▁▁▁▁▁▃▅▅▅| max 49.0%') end it '!asciitemp' do @@ -319,7 +319,7 @@ expect(replies[3]).to eq("Portland, OR 24 hr temps: 28.3°F |\u000306_▁▃\u000310▅▇█\u000303██\u000310██▇▅\u000306▅▃▃▃▃▃▃▁▁▁▁\u0003| 28.4°F Range: 28.3°F - 39.0°F") expect(replies[4]).to eq("Portland, OR 48h wind direction 4.3 mph|\u000306↓\u000310↙←\u000311↖↑↗\u000308→↘\u000311↓←←←←←←\u000310←←←←←←←\u000306←←←←←\u000302←←←↙↙↙↙↓↓↓\u000306↓↓↓↓↓↓↓↓↙↙\u0003|4.18 mph Range: 1.39 mph - 12.71 mph") expect(replies[5]).to eq("Portland, OR 8 day sun forecast |\u000308█\u000309▃\u000308▇\u000309▁_\u000307▅\u000309▃\u000307▅\u0003|") - expect(replies[6]).to eq("Portland, OR 24h cloud cover |___________▁▁▁▁▁▁▁▁▃▅▅▅|") + expect(replies[6]).to eq("Portland, OR 24h cloud cover |___________▁▁▁▁▁▁▁▁▃▅▅▅| max 49.0%") expect(replies[7]).to eq("Portland, OR 48 hr snows |\u000302_______________________▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁_\u0003| max 4.0%") end