Skip to content

Commit

Permalink
Abstracted the max get out, needs some generalization.
Browse files Browse the repository at this point in the history
  • Loading branch information
onewheelskyward committed Aug 5, 2015
1 parent d82a630 commit 6160114
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/lita/handlers/forecasts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def ascii_rain_forecast(forecast)

def ansi_rain_forecast(forecast)
str = do_the_rain_chance_thing(forecast, ansi_chars, 'precipProbability') #, 'probability', get_rain_range_colors)
"rain probability #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s}"
max_str = get_max_rain_chance(forecast)
"rain probability #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s} #{max_str}"
end

def ansi_rain_intensity_forecast(forecast)
Expand All @@ -19,6 +20,16 @@ def ansi_humidity_forecast(forecast)
do_the_humidity_thing(forecast, ansi_chars, 'humidity') #, 'probability', get_rain_range_colors)
end

def get_max_rain_chance(forecast)
unless forecast['minutely'].nil?
data_points = []
forecast['minutely']['data'].each do |data_point|
data_points.push data_point['precipProbability']
end
"max #{data_points.max * 100}%"
end
end

def do_the_rain_chance_thing(forecast, chars, key, use_color = config.colors)
if forecast['minutely'].nil?
return 'No minute-by-minute data available.'
Expand Down Expand Up @@ -49,8 +60,6 @@ def do_the_rain_chance_thing(forecast, chars, key, use_color = config.colors)
str = get_colored_string(data, key, str, get_rain_range_colors)
end

# Add max
str += " max #{data_points.max * 100}%"
str
end

Expand Down

0 comments on commit 6160114

Please sign in to comment.