aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuc Donnet2018-04-10 17:40:17 +0200
committerGitHub2018-04-10 17:40:17 +0200
commitb40a3e02db22762931a7e8e12187d5ba5bbc5618 (patch)
treee731d5f62896fcdbc37c6ba8bea666a01033883e /lib
parent537a5078657ead0b89aa5220c05dfbc01ae94dca (diff)
parent543e3d051731ef50f7420d03dd03849054925f32 (diff)
downloadchouette-core-b40a3e02db22762931a7e8e12187d5ba5bbc5618.tar.bz2
Merge pull request #460 from af83/6360-workbenchimport-display
6360 Add checks on calendars during WorkbenchImport
Diffstat (limited to 'lib')
-rw-r--r--lib/stif/netex_file.rb28
1 files changed, 18 insertions, 10 deletions
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
+ # <netex:ValidBetween>
+ # <netex:FromDate>2017-03-01</netex:FromDate>
+ # <netex:ToDate>2017-03-31</netex:ToDate>
+ # </netex:ValidBetween>
+ 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)
- # <netex:ValidBetween>
- # <netex:FromDate>2017-03-01</netex:FromDate>
- # <netex:ToDate>2017-03-31</netex:ToDate>
- # </netex:ValidBetween>
- 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)