Class: SoutheasternDailyPerformance::AffectedService
- Inherits:
-
Object
- Object
- SoutheasternDailyPerformance::AffectedService
- Defined in:
- lib/southeastern_daily_performance/affected_service.rb
Instance Attribute Summary collapse
-
#effect_on_service ⇒ Object
readonly
Returns the value of attribute effect_on_service.
-
#reason_for_disruption ⇒ Object
readonly
Returns the value of attribute reason_for_disruption.
-
#scheduled_destination_station ⇒ Object
readonly
Returns the value of attribute scheduled_destination_station.
-
#scheduled_start_station ⇒ Object
readonly
Returns the value of attribute scheduled_start_station.
-
#scheduled_start_time ⇒ Object
readonly
Returns the value of attribute scheduled_start_time.
Instance Method Summary collapse
- #==(incident) ⇒ Object
-
#initialize(reason_for_disruption, incident_text) ⇒ AffectedService
constructor
A new instance of AffectedService.
Constructor Details
#initialize(reason_for_disruption, incident_text) ⇒ AffectedService
Returns a new instance of AffectedService.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/southeastern_daily_performance/affected_service.rb', line 8 def initialize(reason_for_disruption, incident_text) @reason_for_disruption = reason_for_disruption incident_text.gsub!(/–/, '-') # Replace ndash with normal dash if incident_text =~ /(\d\d:\d\d) (.*?) ?(?:-|to|\?) (.*)/ @scheduled_start_time, @scheduled_start_station = $1, $2 destination_and_effect_on_service = $3 @scheduled_start_station.gsub!(/[^a-zA-Z ]/, '') reasons = [ 'cancelled', 'started', 'delayed by', 'did not call', 'terminated( at)?', 'diverted', 'ran fast', 'called' ] matches = reasons.collect do |reason| destination_and_effect_on_service =~ /#{reason}/i end if matches.compact.min && reason = reasons[matches.index(matches.compact.min)] destination_and_effect_on_service =~ /(.*) (#{reason}.*)/i else unless destination_and_effect_on_service.split(' ').length == 1 warn "Warning. Unknown, or missing, affect on service: '#{incident_text}'" end destination_and_effect_on_service =~ /(.*)/ end @scheduled_destination_station, @effect_on_service = $1, ($2||'') else warn "Warning. Cannot parse service details: '#{incident_text}'" end end |
Instance Attribute Details
#effect_on_service ⇒ Object (readonly)
Returns the value of attribute effect_on_service.
6 7 8 |
# File 'lib/southeastern_daily_performance/affected_service.rb', line 6 def effect_on_service @effect_on_service end |
#reason_for_disruption ⇒ Object (readonly)
Returns the value of attribute reason_for_disruption.
4 5 6 |
# File 'lib/southeastern_daily_performance/affected_service.rb', line 4 def reason_for_disruption @reason_for_disruption end |
#scheduled_destination_station ⇒ Object (readonly)
Returns the value of attribute scheduled_destination_station.
5 6 7 |
# File 'lib/southeastern_daily_performance/affected_service.rb', line 5 def scheduled_destination_station @scheduled_destination_station end |
#scheduled_start_station ⇒ Object (readonly)
Returns the value of attribute scheduled_start_station.
5 6 7 |
# File 'lib/southeastern_daily_performance/affected_service.rb', line 5 def scheduled_start_station @scheduled_start_station end |
#scheduled_start_time ⇒ Object (readonly)
Returns the value of attribute scheduled_start_time.
5 6 7 |
# File 'lib/southeastern_daily_performance/affected_service.rb', line 5 def scheduled_start_time @scheduled_start_time end |
Instance Method Details
#==(incident) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/southeastern_daily_performance/affected_service.rb', line 35 def ==(incident) self.reason_for_disruption == incident.reason_for_disruption and self.scheduled_start_time == incident.scheduled_start_time and self.scheduled_start_station == incident.scheduled_start_station and self.scheduled_destination_station == incident.scheduled_destination_station and self.effect_on_service == incident.effect_on_service end |