Class: NationalRail::LiveDepartureBoards::SummaryRow

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ SummaryRow

Returns a new instance of SummaryRow.



10
11
12
# File 'lib/national-rail/live_departure_boards.rb', line 10

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



9
10
11
# File 'lib/national-rail/live_departure_boards.rb', line 9

def attributes
  @attributes
end

Instance Method Details

#[](key) ⇒ Object



13
14
15
# File 'lib/national-rail/live_departure_boards.rb', line 13

def [](key)
  @attributes[key]
end

#detailsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/national-rail/live_departure_boards.rb', line 16

def details
  url = "http://ojp.nationalrail.co.uk/en/s/ldbdetailsJson"
  params = { "departing" => "false", "serviceId" => @attributes[:service_id] }
  uri = URI.parse("#{url}?#{params.to_query}")
  response = Net::HTTP.get_response(uri)
  json = ActiveSupport::JSON.decode(response.body)
  json["trains"].map do |row|
    {
      :departs => row[1],
      :station => row[2],
      :status => row[3..4],
      :platform => row[5]
    }
  end
end