Class: NationalRail::JourneyPlanner::SummaryRow

Inherits:
Object
  • Object
show all
Defined in:
lib/national-rail/journey_planner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent, date, departure_time, number_of_changes, link, status) ⇒ SummaryRow

Returns a new instance of SummaryRow.



100
101
102
103
104
# File 'lib/national-rail/journey_planner.rb', line 100

def initialize(agent, date, departure_time, number_of_changes, link, status)
  @agent, @date = agent, date
  @departure_time, @number_of_changes, @link = departure_time, number_of_changes, link
  @status = status
end

Instance Attribute Details

#departure_timeObject (readonly)

Returns the value of attribute departure_time.



98
99
100
# File 'lib/national-rail/journey_planner.rb', line 98

def departure_time
  @departure_time
end

#number_of_changesObject (readonly)

Returns the value of attribute number_of_changes.



98
99
100
# File 'lib/national-rail/journey_planner.rb', line 98

def number_of_changes
  @number_of_changes
end

Instance Method Details

#cancelled?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/national-rail/journey_planner.rb', line 106

def cancelled?
  @status =~ %r{cancelled}i
end

#detailsObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/national-rail/journey_planner.rb', line 110

def details
  return {} if number_of_changes.to_i > 0
  return {} if cancelled?
  @agent.transact do
    details_page = @link.click
    JourneyPlanner.capture(details_page, "details.html")
    parser = DetailsPageParser.new(details_page.doc, @date)
    begin
      parser.parse
    rescue => e
      JourneyPlanner.capture(details_page, "details-error.html")
      page_html = TidyFFI::Tidy.new(details_page.parser.to_html).clean
      raise ParseError.new(e, page_html)
    end
  end
end