module QldTranslinkDepartures
Constants
- STYLE_TITLE
Public Instance Methods
Source
# File lib/qld_translink_departures.rb, line 61 def format_alerts(alerts) if alerts.empty? return IrcReply.card( tag: "QLD", title: "TransLink alerts", body_lines: ["No active service alerts."], heading_style: STYLE_TITLE ) end lines = alerts.first(QldConfig::MAX_ALERTS).map.with_index(1) do |row, index| text = row[:header] text += " โ #{row[:description]}" unless row[:description].to_s.empty? "#{index}. #{text[0, 180]}" end IrcReply.card( tag: "QLD", title: "TransLink alerts", body_lines: lines, footer_parts: ["GTFS-RT Alerts", "TransLink"], heading_style: STYLE_TITLE ) end
Source
# File lib/qld_translink_departures.rb, line 37 def format_departures(stop_name:, rows:) if rows.empty? return IrcReply.card( tag: "QLD", title: "Departures ยท #{stop_name}", body_lines: ["No real-time departures found for this stop."], heading_style: STYLE_TITLE ) end lines = rows.map do |row| label = row[:route_id].to_s.empty? ? "service" : "route #{row[:route_id]}" delay = row[:delay_sec].positive? ? " (+#{row[:delay_sec] / 60}m)" : "" "#{row[:time].getlocal('+10:00').strftime('%H:%M')} โ #{label}#{delay}" end IrcReply.card( tag: "QLD", title: "Departures ยท #{stop_name}", body_lines: lines, footer_parts: ["GTFS-RT TripUpdates", "TransLink"], heading_style: STYLE_TITLE ) end
Source
# File lib/qld_translink_departures.rb, line 15 def format_stops(stops, query:) if stops.empty? return IrcReply.card( tag: "QLD", title: "TransLink stops ยท #{query}", body_lines: ["No stops found."], heading_style: STYLE_TITLE ) end lines = stops.map.with_index(1) do |row, index| "#{index}. #{row[:name]} (#{row[:stop_id]})" end IrcReply.card( tag: "QLD", title: "TransLink stops ยท #{query}", body_lines: lines, footer_parts: ["TransLink GTFS", "SEQ"], heading_style: STYLE_TITLE ) end
Source
# File lib/qld_translink_departures.rb, line 85 def lookup_departures(query, fetch: nil, region: QldConfig::DEFAULT_REGION, time: Time.now) stops = QldTranslinkGtfs.search_stops(query, fetch: fetch, limit: 3) return { error: "Stop not found โ try !qld stop #{query}" } if stops.empty? stop_ids = stops.map { |row| row[:stop_id] } message = QldTranslinkRt.fetch_feed(region: region, feed: QldTranslinkRt::FEED_TRIP_UPDATES, fetch: fetch) rows = QldTranslinkRt.departures_for_stops(stop_ids, message: message, time: time) { stop_name: stops.first[:name], rows: rows } end