module BomForecastReport
BomForecastReport โ IRC reply cards for BOM forecast lookups.
Constants
- STYLE_TITLE
Public Instance Methods
Source
# File lib/bom_forecast_report.rb, line 59 def format_current(current) return nil unless current parts = [] parts << current[:temperature] if current[:temperature] && !current[:temperature].empty? if current[:feels_like] && !current[:feels_like].empty? parts << "Feels #{current[:feels_like]}" end if current[:humidity] && !current[:humidity].empty? parts << "Humidity #{current[:humidity]}" end if current[:wind_direction] && !current[:wind_direction].empty? wind = "Wind #{current[:wind_direction]}" wind += " #{current[:wind_speed]}" if current[:wind_speed] && !current[:wind_speed].empty? parts << wind end return nil if parts.empty? line = "Current: #{parts.join(', ')}" line += " (#{current[:observed_at]})" if current[:observed_at] && !current[:observed_at].empty? description = format_day_description(current[:description]) line += ". #{description}" if description line end
Source
# File lib/bom_forecast_report.rb, line 39 def format_day_description(text) value = text.to_s.strip value.empty? ? nil : value end
Source
# File lib/bom_forecast_report.rb, line 44 def format_day_line(day) parts = [day[:period].to_s] parts << day[:condition] if day[:condition] if day[:min] && day[:max] parts << "Min #{day[:min]} / Max #{day[:max]}" elsif day[:max] parts << "Max #{day[:max]}" elsif day[:min] parts << "Min #{day[:min]}" end description = format_day_description(day[:description] || day[:summary]) parts << description if description parts.join(" โ ") end
Source
# File lib/bom_forecast_report.rb, line 84 def format_report(forecast, current:, days: 1, state: nil) lines = [] lines << weather_banner(place: forecast[:place], issued: forecast[:issued], state: state) if current today_description = BomForecast.current_forecast_description(forecast[:days]) current_with_description = today_description ? current.merge(description: today_description) : current current_line = format_current(current_with_description) lines << current_line if current_line end filtered_days = BomForecast.filter_forecast_days(forecast[:days], days: days) rain_line = BomRainReport.format_rain_forecast(BomForecast.rain_forecast_days(forecast[:days], days: days)) filtered_days.each do |day| lines << format_day_line(day) end lines << rain_line if rain_line lines.compact.join("\n") end
Source
# File lib/bom_forecast_report.rb, line 13 def place_label(place, state = nil) name = place.to_s.strip return "" if name.empty? st = state.to_s.strip st.empty? ? name : "#{name} #{st.upcase}" end