class DCMetro::Cli::Application
Public Instance Methods
alerts()
click to toggle source
# File lib/dcmetro/cli/application.rb, line 13 def alerts # # $dcmetro alerts # => *** Alert! Alert! *** x = DCMetro::Information.new alerts = parse_json x.alerts display_alerts alerts end
line(color=nil)
click to toggle source
# File lib/dcmetro/cli/application.rb, line 25 def line color=nil # # $dcmetro line # => Orange, Blue, Silver, Red, etc ... # # $dcmetro line Red # => Displays the stations on the Red Line x = DCMetro::Information.new if !color.nil? line = parse_json x.line(color) line["Stations"].each { |station| puts station['Name']} else lines = parse_json x.line lines["Lines"].each do |line| color = get_color(line['LineCode']) puts "#{color}#{line['DisplayName']}#{COLOR_OFF}" end end end
lines(color=nil)
click to toggle source
# File lib/dcmetro/cli/application.rb, line 49 def lines color=nil invoke :line end
station(from, to=nil)
click to toggle source
# File lib/dcmetro/cli/application.rb, line 55 def station(from, to=nil) # # $dcmetro station Greenbelt # => Displays the departure and arrival times at the Greenbelt Station # # $dcmetro station Greenbelt -a # => Displays the alerts, departure and arrival times at the Greenbelt Station # x = DCMetro::Information.new if options[:alerts] y = parse_json x.alerts display_alerts y end if to.nil? x = parse_json x.station(from) train_time = x['Trains'].empty? ? "Sorry, there is no information for #{from}." : display_trains(x['Trains']) puts train_time if !train_time.kind_of?(Array) train_time else x = x.station(from,to) y = parse_json x display_travel_info y end end
Private Instance Methods
display_alerts(alerts)
click to toggle source
# File lib/dcmetro/cli/application.rb, line 109 def display_alerts alerts # # Formats the display of the alerts if alerts['Incidents'].empty? puts "*** No alerts reported. ***" else puts "#{RED}*** ALERT! ALERT! ***#{COLOR_OFF}" alerts['Incidents'].each { |incident| puts "#{incident["Description"]}\n\n"} end end
display_trains(trains)
click to toggle source
# File lib/dcmetro/cli/application.rb, line 121 def display_trains trains # # Formats the display of the train arrival and departures puts "===== #{trains[0]['LocationName']} =====" trains.each do |prediction| puts "Line: #{prediction['Line']} | Towards: #{prediction['DestinationName']} | Arriving: #{prediction['Min']}" end end
display_travel_info(information)
click to toggle source
# File lib/dcmetro/cli/application.rb, line 131 def display_travel_info information information = information['StationToStationInfos'][0] railFare = information['RailFare'] puts "Distance: #{information['CompositeMiles']} Miles\n" puts "Estimate Travel Time: #{information['RailTime']} Minutes\n" puts "\n*** Fare Information ***\nOff Peak Time: $#{railFare['OffPeakTime']}\nPeak Time: $#{railFare['PeakTime']}\nSenior/Disabled: $#{railFare['SeniorDisabled']}" end
get_color(line_code)
click to toggle source
# File lib/dcmetro/cli/application.rb, line 88 def get_color line_code case line_code when "GR" GREEN when "BL" BLUE when "OR" ORANGE when "SV" SILVER when "YL" YELLOW else RED end end
parse_json(response)
click to toggle source
# File lib/dcmetro/cli/application.rb, line 105 def parse_json response JSON.parse(response) end