module GovauRoutes
Constants
- STYLE_TITLE
Public Instance Methods
Source
# File lib/govau_routes.rb, line 18 def fetch_routes(devid:, key:, fetch: nil) path = "/v3/routes/route_type/#{GovauConfig::ROUTE_TYPE_TRAIN}" url = GovauPtv.build_url(path, devid: devid, key: key) payload = GovauPtv.fetch_json(url, fetch: fetch) parse_routes(payload) rescue StandardError [] end
Source
# File lib/govau_routes.rb, line 38 def format_routes(rows) lines = [ IrcFormat.report_header( tag: "GOVAU", title: "Victoria ยท metro train lines", style: STYLE_TITLE ) ] if rows.empty? lines << "No train lines returned." else rows.first(GovauConfig::MAX_ROUTES).each do |row| lines << row[:name] end end count = rows.length footer_count = count.zero? ? "0 lines" : "#{count} lines" lines << IrcFormat.report_footer(footer_count, "PTV ยท data.gov.au") lines.join("\n") end
Source
# File lib/govau_routes.rb, line 27 def parse_routes(payload) Array(payload["routes"]).filter_map do |row| next unless row.is_a?(Hash) name = GovauPtv.first_present(row["route_number"], row["route_name"]) next if name.empty? { route_id: row["route_id"], name: name } end end