aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stif/netex_file.rb
diff options
context:
space:
mode:
authorRobert2017-11-27 11:24:31 +0100
committerRobert2017-12-14 15:34:46 +0100
commit424496bc6e7b6f94b0f34d3c11fb95fd7f6088c5 (patch)
tree93b48c0c97478ead12d0fc61d625247a1b878d62 /lib/stif/netex_file.rb
parente82600d2efcc90f327b90d04239fe41b80031ad4 (diff)
downloadchouette-core-424496bc6e7b6f94b0f34d3c11fb95fd7f6088c5.tar.bz2
Refs: #5006@12h;
Implementing allowed vs foreign line lookup for the zip service - Adapting `lib/stif/netex_file.rb` to expose the already implemented matching - `app/services/zip_service.rb` augmented to check for allowed lines and returning forbidden lines - Specs with fixtures and using the beforementioned new zip support in the specs - Fixture directories for the new specs
Diffstat (limited to 'lib/stif/netex_file.rb')
-rw-r--r--lib/stif/netex_file.rb65
1 files changed, 35 insertions, 30 deletions
diff --git a/lib/stif/netex_file.rb b/lib/stif/netex_file.rb
index a977c1ad3..b3e093727 100644
--- a/lib/stif/netex_file.rb
+++ b/lib/stif/netex_file.rb
@@ -2,8 +2,9 @@ module STIF
class NetexFile
CALENDAR_FILE_NAME = 'calendriers.xml'
- LINE_FILE_FORMAT = /^offre_.*\.xml$/
- XML_NAME_SPACE = "http://www.netex.org.uk/netex"
+ LINE_FILE_FORMAT = %r{\A offre_ (.*?) _ .* \. xml \z}x
+ XML_NAME_SPACE = "http://www.netex.org.uk/netex"
+
def initialize(file_name)
@file_name = file_name
@@ -22,49 +23,53 @@ module STIF
frames[entry_dir_name].parse_calendars(stream.read)
end
when LINE_FILE_FORMAT
- frames[entry_dir_name].add_offer_file(entry_file_name)
+ frames[entry_dir_name].add_offer_file($1)
end
end
end
frames.values
end
- end
+ class Frame
- class NetexFile::Frame
+ class << self
+ def get_line_object_id file_name
+ base_name = File.split(file_name).last
+ STIF::NetexFile::LINE_FILE_FORMAT.match(base_name).try(:[], 1)
+ end
+ end
- attr_accessor :name
+ attr_accessor :name
- def initialize(name)
- @name = name
- end
+ def initialize(name)
+ @name = name
+ 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
+ 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))
+ def add_offer_file(line_object_id)
+ line_refs << line_object_id
end
- end
- def add_offer_file(file_name)
- if file_name =~ /^offre_([^_]*)_/
- line_refs << $1
+ def periods
+ @periods ||= []
end
- end
- def periods
- @periods ||= []
- end
+ def line_refs
+ @line_refs ||= []
+ end
- def line_refs
- @line_refs ||= []
end
-
end
end