Class: SoutheasternDailyPerformance::DailyPerformanceReport
- Inherits:
-
Object
- Object
- SoutheasternDailyPerformance::DailyPerformanceReport
- Defined in:
- lib/southeastern_daily_performance/daily_performance_report.rb
Instance Method Summary collapse
- #actual_services ⇒ Object
- #affected_services ⇒ Object
- #date ⇒ Object
-
#initialize(html) ⇒ DailyPerformanceReport
constructor
A new instance of DailyPerformanceReport.
- #scheduled_services ⇒ Object
- #services_within_five_minutes_of_schedule ⇒ Object
- #to_csv(type = nil) ⇒ Object
Constructor Details
#initialize(html) ⇒ DailyPerformanceReport
Returns a new instance of DailyPerformanceReport.
8 9 10 11 |
# File 'lib/southeastern_daily_performance/daily_performance_report.rb', line 8 def initialize(html) html = html.gsub(%r! !, ' ') @doc = Hpricot(html) end |
Instance Method Details
#actual_services ⇒ Object
28 29 30 |
# File 'lib/southeastern_daily_performance/daily_performance_report.rb', line 28 def actual_services report[/of which (\d+) ran/, 1].to_i end |
#affected_services ⇒ Object
36 37 38 |
# File 'lib/southeastern_daily_performance/daily_performance_report.rb', line 36 def affected_services AffectedServicesReport.new(report_container.inner_html).affected_services end |
#date ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/southeastern_daily_performance/daily_performance_report.rb', line 13 def date date = (@doc/'h1').inner_text date.gsub!(/\?/, ' ') if date =~ /(.+?) (\d+) (.+)/ elsif (@doc/'h2').inner_text =~ /(.+?) (\d+) (.+)/ end day_name, day, month_name = $1, $2, $3 date = [day, month_name[0..2].downcase, '2010'].join('-') Date.parse(date) end |
#scheduled_services ⇒ Object
24 25 26 |
# File 'lib/southeastern_daily_performance/daily_performance_report.rb', line 24 def scheduled_services report[/(\d+) (train )?services were scheduled/, 1].to_i end |
#services_within_five_minutes_of_schedule ⇒ Object
32 33 34 |
# File 'lib/southeastern_daily_performance/daily_performance_report.rb', line 32 def services_within_five_minutes_of_schedule report[/(\d+\.?\d+?)% of services ran within 5 minutes of schedule/, 1].to_f end |
#to_csv(type = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/southeastern_daily_performance/daily_performance_report.rb', line 40 def to_csv(type=nil) if "#{type}" == 'overview' CSV.generate_line [date, scheduled_services, actual_services, services_within_five_minutes_of_schedule] else affected_services.collect do |service| CSV.generate_line [date, service.reason_for_disruption, service.scheduled_start_time, service.scheduled_start_station, service.scheduled_destination_station, service.effect_on_service] end.join("\n") end end |