From 27442a9ffe40d0f548b1dc99ab917a8d8b0a02a2 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 9 Apr 2018 11:20:56 +0200 Subject: Refs #6360; Add checks on calendars during WorkbenchImport --- lib/stif/netex_file.rb | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'lib/stif') diff --git a/lib/stif/netex_file.rb b/lib/stif/netex_file.rb index db0801bbe..1e78ca04a 100644 --- a/lib/stif/netex_file.rb +++ b/lib/stif/netex_file.rb @@ -47,6 +47,23 @@ module STIF base_name = File.basename(file_name) STIF::NetexFile::LINE_FILE_FORMAT.match(base_name).try(:[], 'line_object_id') end + + def parse_calendars calendars + # + # 2017-03-01 + # 2017-03-31 + # + xml = Nokogiri::XML(calendars) + from_date = nil + to_date = nil + xml.xpath("//netex:ValidBetween", "netex" => NetexFile::XML_NAME_SPACE).each do |valid_between| + from_date = valid_between.xpath("netex:FromDate").try :text + to_date = valid_between.xpath("netex:ToDate").try :text + end + from_date = from_date && Date.parse(from_date) + to_date = to_date && Date.parse(to_date) + Range.new from_date, to_date + end end attr_accessor :name @@ -56,16 +73,7 @@ module STIF end def parse_calendars(calendars) - # - # 2017-03-01 - # 2017-03-31 - # - xml = Nokogiri::XML(calendars) - xml.xpath("//netex:ValidBetween", "netex" => NetexFile::XML_NAME_SPACE).each do |valid_between| - from_date = valid_between.xpath("netex:FromDate").try :text - to_date = valid_between.xpath("netex:ToDate").try :text - periods << Range.new(Date.parse(from_date), Date.parse(to_date)) - end + periods << self.class.parse_calendars(calendars) end def add_offer_file(line_object_id) -- cgit v1.2.3