module QuakeFeed
Constants
- FEED_URL
- STYLE_TITLE
Public Instance Methods
Source
# File lib/quake_feed.rb, line 14 def fetch_recent(fetch: nil) payload = if fetch JSON.parse(fetch.call(FEED_URL)) else RabbotHttp.fetch_json(FEED_URL) end parse_geojson(payload) rescue StandardError [] end
Source
# File lib/quake_feed.rb, line 51 def format_recent(events) lines = [ IrcFormat.report_header(tag: "QUAKE", title: "Recent AU-region events", style: STYLE_TITLE) ] if events.empty? lines << "No recent earthquakes in the AU region." else events.first(5).each do |event| lines << "M#{event[:magnitude]} โ #{event[:place]} โ #{format_time(event[:time])}" end end lines << IrcFormat.report_footer("USGS ยท AU region") lines.join("\n") end
Source
# File lib/quake_feed.rb, line 43 def format_time(ms) return "unknown time" if ms.nil? Time.at(ms.to_i / 1000).utc.strftime("%Y-%m-%d %H:%M UTC") rescue StandardError "unknown time" end
Source
# File lib/quake_feed.rb, line 25 def parse_geojson(payload) return [] unless payload.is_a?(Hash) Array(payload["features"]).filter_map do |feature| next unless feature.is_a?(Hash) props = feature["properties"] || {} coords = feature.dig("geometry", "coordinates") || [] { id: feature["id"].to_s, magnitude: props["mag"].to_f, place: props["place"].to_s.strip, time: props["time"], depth: coords[2] } end end