module RadarLookup
RadarLookup — orchestrate geocode, nearest radar, fetch, render, and IRC report. Public: lookup, parse_location Depends: geo_lookup, bom_radar_* modules, radar_report Tests: test/plugins/radar_test.rb
Public Instance Methods
Source
# File lib/radar_lookup.rb, line 24 def lookup(location, fetch: nil, search: Geocoder.method(:search)) place_text = parse_location(location) return RadarReport.build_usage unless place_text result = GeoLookup.lookup_place(place_text, search: search) return RadarReport.build_not_found(place_text) unless result coords = GeoLookup.coordinates_for(result) return RadarReport.build_not_found(place_text) unless coords lat, lon = coords site_match = BomRadarSites.nearest(lat, lon) site = site_match[:site] edge_note = site_match[:edge] ? "Near edge of #{site[:name]} radar coverage." : nil place_label = GeoLookup.location_label(result) fetcher = fetch || BomRadarFetch.default_fetch frame = BomRadarFetch.fetch_frame(site[:product_id], fetch: fetcher) return RadarReport.build_error("Radar image unavailable right now.") unless frame background = BomRadarFetch.fetch_background(site[:product_id], fetch: fetcher) grid = BomRadarImage.decode(frame[:bytes]) render = BomRadarRender.render_map( grid, background_data: background, site: site, product_id: site[:product_id], query_lat: lat, query_lon: lon ) observed = BomRadarFetch.format_timestamp(frame[:timestamp]) RadarReport.build_report( place: place_label, site: site, map_lines: render[:lines], town_summaries: render[:summaries], observed: observed, edge_note: edge_note ) rescue StandardError RadarReport.build_error("Radar lookup failed.") end
Source
# File lib/radar_lookup.rb, line 19 def parse_location(text) value = text.to_s.strip value.empty? ? nil : value end