diff options
| author | Robert | 2017-11-27 11:24:31 +0100 |
|---|---|---|
| committer | Robert | 2017-12-14 15:34:46 +0100 |
| commit | 424496bc6e7b6f94b0f34d3c11fb95fd7f6088c5 (patch) | |
| tree | 93b48c0c97478ead12d0fc61d625247a1b878d62 /app/services/zip_service.rb | |
| parent | e82600d2efcc90f327b90d04239fe41b80031ad4 (diff) | |
| download | chouette-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 'app/services/zip_service.rb')
| -rw-r--r-- | app/services/zip_service.rb | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/app/services/zip_service.rb b/app/services/zip_service.rb index 7a4bdad1b..6596f6961 100644 --- a/app/services/zip_service.rb +++ b/app/services/zip_service.rb @@ -1,12 +1,16 @@ class ZipService - class Subdir < Struct.new(:name, :stream, :spurious) + class Subdir < Struct.new(:name, :stream, :spurious, :foreign_lines) + def ok? + foreign_lines.empty? && spurious.empty? + end end - attr_reader :current_key, :current_output, :current_spurious, :yielder + attr_reader :allowed_lines, :current_key, :foreign_lines, :current_output, :current_spurious, :yielder - def initialize data + def initialize data, allowed_lines @zip_data = StringIO.new(data) + @allowed_lines = allowed_lines @current_key = nil @current_output = nil end @@ -36,6 +40,7 @@ class ZipService def add_to_current_output entry return if is_spurious! entry.name + return if is_foreign_line! entry.name current_output.put_next_entry entry.name write_to_current_output entry.get_input_stream end @@ -52,20 +57,22 @@ class ZipService current_key, # Second part of the solution, yield the closed stream current_output.close_buffer, - current_spurious) + current_spurious, + foreign_lines) end end def open_new_output entry_key @current_key = entry_key # First piece of the solution, use internal way to create a Zip::OutputStream - @current_output = Zip::OutputStream.new(StringIO.new(''), true, nil) + @current_output = Zip::OutputStream.new(StringIO.new(''), true, nil) @current_spurious = [] + @foreign_lines = [] end def entry_key entry # last dir name File.dirname.split("/").last - entry.name.split('/', -1)[-2] + entry.name.split('/').first end def is_spurious! entry_name @@ -75,4 +82,12 @@ class ZipService current_spurious << segments.second return true end + + def is_foreign_line! entry_name + STIF::NetexFile::Frame.get_line_object_id(entry_name).tap do | line_object_id | + return nil unless line_object_id + return nil if line_object_id.in? allowed_lines + foreign_lines << line_object_id + end + end end |
