module SunbusFormat
Constants
- STYLE_TITLE
Public Instance Methods
Source
# File lib/sunbus/format.rb, line 126 def format_alerts(items, region:) label = SunbusConfig.region_label(region) body = if items.empty? ["No active bus service alerts."] else items.map do |row| severity = row[:description].to_s.strip severity.empty? ? row[:title] : "#{row[:title]} โ #{severity}" end end IrcReply.card( tag: "SUNBUS", title: "Alerts ยท #{label}", body_lines: body, footer_parts: items.empty? ? nil : ["TransLink RSS", label], heading_style: STYLE_TITLE ) end
Source
# File lib/sunbus/format.rb, line 97 def format_connecting_trip(result, region:, service_date: nil, day_offset: 0) label = SunbusConfig.region_label(region) title = trip_title(result, service_date: service_date, day_offset: day_offset) body = [] result[:legs].each_with_index do |leg, index| route = leg[:route_short_name].to_s.empty? ? "service" : "route #{leg[:route_short_name]}" body << "Depart โ #{leg[:depart]} (#{route})" if index < result[:legs].length - 1 transfer = result[:transfer_stop] body << "Arrive โ #{leg[:arrive]} โ change at #{transfer[:name]}" else body << "Arrive โ #{leg[:arrive]}" end end transfers = result[:legs].length - 1 body << "Duration โ #{result[:duration_min]} min ยท #{transfers} transfer#{transfers == 1 ? '' : 's'}" IrcReply.card( tag: "SUNBUS", title: title, body_lines: body, footer_parts: ["GTFS schedule ยท connecting", label], heading_style: STYLE_TITLE ) end
Source
# File lib/sunbus/format.rb, line 145 def format_notices(items, region:) label = SunbusConfig.region_label(region) body = if items.empty? ["No service notices for this region."] else items.map.with_index(1) do |row, index| text = row[:title] desc = TextUtil.squish(row[:description]) text += " โ #{desc}" unless desc.empty? "#{index}. #{text[0, 180]}" end end IrcReply.card( tag: "SUNBUS", title: "Notices ยท #{label}", body_lines: body, footer_parts: items.empty? ? nil : ["TransLink RSS", label], heading_style: STYLE_TITLE ) end
Source
# File lib/sunbus/format.rb, line 122 def format_ringroad(result) SunbusRingRoad.format_report(**result) end
Source
# File lib/sunbus/format.rb, line 22 def format_stops(stops, query:, region:) label = SunbusConfig.region_label(region) body = stops.empty? ? ["No stops found."] : stops.map.with_index(1) { |row, index| "#{index}. #{row[:name]} (#{row[:stop_id]})" } footer = stops.empty? ? nil : ["GTFS schedule", label] IrcReply.card( tag: "SUNBUS", title: "Stops ยท #{query} ยท #{label}", body_lines: body, footer_parts: footer, heading_style: STYLE_TITLE ) end
Source
# File lib/sunbus/format.rb, line 35 def format_suburb_stops(stops, suburb:, region:) label = SunbusConfig.region_label(region) title = TextUtil.title_words(suburb) body = stops.empty? ? ["No stops found in this suburb."] : stops.map.with_index(1) { |row, index| "#{index}. #{row[:name]} (#{row[:stop_id]})" } footer = stops.empty? ? nil : ["#{stops.length} stops ยท GTFS schedule", label] IrcReply.card( tag: "SUNBUS", title: "Suburb ยท #{title} ยท #{label}", body_lines: body, footer_parts: footer, heading_style: STYLE_TITLE ) end
Source
# File lib/sunbus/format.rb, line 49 def format_times(stop_name:, rows:, region:, service_date: nil, day_offset: 0) label = SunbusConfig.region_label(region) title = times_title(stop_name, service_date: service_date, day_offset: day_offset) if rows.empty? return IrcReply.card( tag: "SUNBUS", title: title, body_lines: ["No upcoming departures found for this stop."], heading_style: STYLE_TITLE ) end lines = rows.map do |row| route = row[:route_short_name].to_s.empty? ? "service" : "route #{row[:route_short_name]}" dest = row[:headsign].to_s.empty? ? "" : " to #{row[:headsign]}" delay = row[:delay_sec].to_i.positive? ? " (+#{row[:delay_sec] / 60}m)" : "" live = row[:live] ? " live" : "" "#{row[:departure_time]} โ #{route}#{dest}#{live}#{delay}" end source = rows.any? { |row| row[:live] } ? "GTFS-RT + schedule" : "GTFS schedule" IrcReply.card( tag: "SUNBUS", title: title, body_lines: lines, footer_parts: [source, label], heading_style: STYLE_TITLE ) end
Source
# File lib/sunbus/format.rb, line 78 def format_trip(result, region:, service_date: nil, day_offset: 0) return format_connecting_trip(result, region: region, service_date: service_date, day_offset: day_offset) if result[:connecting] label = SunbusConfig.region_label(region) title = trip_title(result, service_date: service_date, day_offset: day_offset) route = result[:route_short_name].to_s.empty? ? "service" : "route #{result[:route_short_name]}" IrcReply.card( tag: "SUNBUS", title: title, body_lines: [ "Depart โ #{result[:depart]} (#{route})", "Arrive โ #{result[:arrive]}", "Duration โ #{result[:duration_min]} min" ], footer_parts: ["GTFS schedule", label], heading_style: STYLE_TITLE ) end
Source
# File lib/sunbus/format.rb, line 166 def help_reply IrcReply.card( tag: "SUNBUS", title: "Townsville & Cairns buses", body_lines: [ "!sunbus times <stop> [tsv|cairns] โ next departures", "!sunbus from <origin> to <dest> โ scheduled trip (with transfers)", "!sunbus stop <name> โ search stops", "!sunbus suburb <name> โ list stops in a suburb", "!sunbus alerts [tsv|cairns] โ bus service status (RSS)", "!sunbus notices [tsv|cairns] โ service notices (RSS)", "!sunbus ringroad โ Townsville Ring Road drive time in one go", "!sunbus help โ this message" ], footer_parts: ["TransLink GTFS ยท RSS", "Kinetic Sunbus"], heading_style: STYLE_TITLE ) end
Source
# File lib/sunbus/format.rb, line 194 def schedule_title(label, name, service_date:, day_offset:) base = label.to_s.strip.empty? ? name.to_s : "#{label} ยท #{name}" return base if day_offset.to_i <= 0 || service_date.nil? "#{base} ยท #{SunbusDayLookup.format_service_date(service_date)}" end
Source
# File lib/sunbus/format.rb, line 185 def times_title(name, service_date:, day_offset:) schedule_title("Times", name, service_date: service_date, day_offset: day_offset) end
Source
# File lib/sunbus/format.rb, line 189 def trip_title(result, service_date:, day_offset:) base = "#{result[:from_stop][:name]} to #{result[:to_stop][:name]}" schedule_title(nil, base, service_date: service_date, day_offset: day_offset) end