Class: NationalRailWrapper::Feeds::KnowledgeBase::Parsers::Stations

Inherits:
Object
  • Object
show all
Defined in:
lib/national_rail_wrapper/feeds/knowledge_base/parsers/stations.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Stations

Returns a new instance of Stations.



6
7
8
# File 'lib/national_rail_wrapper/feeds/knowledge_base/parsers/stations.rb', line 6

def initialize(data)
  @data = data
end

Instance Method Details

#to_jsonObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/national_rail_wrapper/feeds/knowledge_base/parsers/stations.rb', line 10

def to_json
  options = Nokogiri::XML::ParseOptions.new.nonet.noent.noblanks.huge
  doc = Nokogiri::XML.parse(@data, nil, nil, options)

  doc.xpath('/xmlns:StationList/xmlns:Station').map do |toc_node|
    {
      name: toc_node.xpath('./xmlns:Name')&.text,
      crs_code: toc_node.css('CrsCode')&.text,
      alternative_identifiers: toc_node.css('AlternativeIdentifiers')&.text,
      sixteen_character_name: toc_node.css('SixteenCharacterName')&.text,
      longitude: toc_node.css('Longitude')&.text,
      latitude: toc_node.css('Latitude')&.text,
      station_operator: toc_node.css('StationOperator')&.text,
      staffing_level: toc_node.css('Staffing/StaffingLevel')&.text,
      closed_circuit_television: toc_node.css('Staffing/ClosedCircuitTelevision')&.text,
      station_facilities: station_facilities(toc_node.css('StationFacilities')),
      # impaired_access: impaired_access(toc_node.css('ImpairedAccess'))
      car_park: car_park(toc_node.css('CarPark'))

    }
  end
end