Class: WMATA::RailIncident

Inherits:
Resource show all
Defined in:
lib/resources/rail_incident.rb

Overview

A resource class representing a rail incident (e.g., garbage on the rails delaying a train).

Available attribute methods:

  • incident_id - ID of the nicident

  • incident_type - Type of the nicident

  • date_updated - Date and time where information was updated.

  • delay_severity - Severity of delay (if any). Can be :minor, :major, or :medium.

  • description - Description what happened.

  • emergency_text - Some text for emergency (if any).

  • start_location_full_name - Station where delay starts.

  • end_location_full_name - Station where delay ends.

  • passenger_delay - Delay in minutes.

Instance Attribute Summary

Attributes inherited from Resource

#attrs

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

endpoint, get_all, #initialize, #method_missing, service, to_query_string

Constructor Details

This class inherits a constructor from WMATA::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class WMATA::Resource

Class Method Details

.get_by_line(line) ⇒ Object

Get all rail incidents by the line; can be a line code string or a Line instance.



22
23
24
25
# File 'lib/resources/rail_incident.rb', line 22

def self.(line)
  @incidents ||= get_all
  @incidents.select {|i| i.line_codes_affected.include?(line.to_s)}
end

Instance Method Details

#date_updatedObject

Get a Time object representing the last time this API data entry was updated.



29
30
31
# File 'lib/resources/rail_incident.rb', line 29

def date_updated
  Time.parse(@attrs['DateUpdated'])
end

#delay_severityObject



48
49
50
# File 'lib/resources/rail_incident.rb', line 48

def delay_severity
  @attrs['DelaySeverity'].to_s.downcase.to_sym
end

#incident_idObject

ID of the incident.



44
45
46
# File 'lib/resources/rail_incident.rb', line 44

def incident_id
  @attrs['IncidentID']
end

#line_codes_affectedObject

Get an array of the line codes affected by this incident.



34
35
36
# File 'lib/resources/rail_incident.rb', line 34

def line_codes_affected
  @attrs['LinesAffected'].split(";").reject {|s| s.empty? || s.nil?}
end

#lines_affectedObject

Get Line instances for the lines affected by this incident.



39
40
41
# File 'lib/resources/rail_incident.rb', line 39

def lines_affected
  @lines_affected = line_codes_affected.map {|l| Line.get(l.strip)}
end