Class: IRail::NMBS::XMLParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-irail/packages/nmbs/parser/xml_parser.rb

Constant Summary collapse

STATION_XPATH =
"//station"
CONNECTION_XPATH =
"//connection"
VEHICLE_XPATH =
"//vehicleinformation"

Class Method Summary collapse

Class Method Details

.parse_connections(xml_string) ⇒ Object



13
14
15
16
17
# File 'lib/ruby-irail/packages/nmbs/parser/xml_parser.rb', line 13

def self.parse_connections(xml_string)
  xml_payload(xml_string, CONNECTION_XPATH).inject([]) do |connections, xml_connection|
    connections << IRail::NMBS::Connection.from_xml(xml_connection.to_s)
  end
end

.parse_liveboard(xml_string) ⇒ Object Also known as: parse_departures, parse_arrivals



24
25
26
# File 'lib/ruby-irail/packages/nmbs/parser/xml_parser.rb', line 24

def self.parse_liveboard(xml_string)
  IRail::NMBS::Liveboard.from_xml(xml_string)
end

.parse_stations(xml_string) ⇒ Object



7
8
9
10
11
# File 'lib/ruby-irail/packages/nmbs/parser/xml_parser.rb', line 7

def self.parse_stations(xml_string)
  xml_payload(xml_string, STATION_XPATH).inject([]) do |stations, xml_station|
    stations << IRail::NMBS::Station.from_xml(xml_station.to_s)
  end
end

.parse_vehicle(xml_string) ⇒ Object



19
20
21
22
# File 'lib/ruby-irail/packages/nmbs/parser/xml_parser.rb', line 19

def self.parse_vehicle(xml_string)
  vehicle = xml_payload(xml_string, VEHICLE_XPATH)
  IRail::NMBS::VehicleInformation.from_xml(vehicle.to_s)
end

.xml_payload(xml_string, xpath) ⇒ Object



33
34
35
36
# File 'lib/ruby-irail/packages/nmbs/parser/xml_parser.rb', line 33

def self.xml_payload(xml_string, xpath)
  xml_payload = Nokogiri::XML(xml_string)
  xml_payload.xpath(xpath)
end