Class: NationalRailWrapper::Feeds::KnowledgeBase::Parsers::NationalServiceIndicators

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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ NationalServiceIndicators

Returns a new instance of NationalServiceIndicators.



6
7
8
# File 'lib/national_rail_wrapper/feeds/knowledge_base/parsers/national_service_indicators.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
# File 'lib/national_rail_wrapper/feeds/knowledge_base/parsers/national_service_indicators.rb', line 10

def to_json
  options = Nokogiri::XML::ParseOptions.new.nonet.noent.noblanks
  doc = Nokogiri::XML.parse(@data, nil, nil, options)
  doc.xpath('/xmlns:NSI/xmlns:TOC').map do |toc_node|
    {
      toc_code: toc_node.xpath('./xmlns:TocCode').first&.content,
      toc_name: toc_node.xpath('./xmlns:TocName').first&.content,
      status: toc_node.xpath('./xmlns:Status').first&.content,
      status_image: toc_node.xpath('./xmlns:StatusImage').first&.content,
      status_description: toc_node.xpath('./xmlns:StatusDescription').first&.content,
      service_groups: service_groups(toc_node.xpath('./xmlns:ServiceGroup')),
      twitter_account: toc_node.xpath('./xmlns:TwitterAccount').first&.content,
      additional_info: toc_node.xpath('./xmlns:AdditionalInfo').first&.content, 
      custom_additional_info: toc_node.xpath('./xmlns:CustomAdditionalInfo').first&.content
    }
  end
end