Class: MdsFileUtils::ZipAnalyzer
- Inherits:
-
Object
- Object
- MdsFileUtils::ZipAnalyzer
- Defined in:
- lib/mds_file_utils/zip_analyzer.rb
Constant Summary collapse
- MAX_MDS_FILE_SIZE =
5MB
5242880
- EXTENSION_REGEX =
/\.zip\z/i
- VALID_COMPOSITE_CONTENTS_REGEX =
/(\.zip|\/|\\)\z/i
Instance Method Summary collapse
- #file_list ⇒ Object
- #file_size ⇒ Object
- #has_valid_extension? ⇒ Boolean
-
#initialize(path, original_filename = path) ⇒ ZipAnalyzer
constructor
A new instance of ZipAnalyzer.
- #is_composite? ⇒ Boolean
- #non_mds_data_in_composite? ⇒ Boolean
- #too_big_for_mds? ⇒ Boolean
- #valid_zip? ⇒ Boolean
Constructor Details
#initialize(path, original_filename = path) ⇒ ZipAnalyzer
Returns a new instance of ZipAnalyzer.
10 11 12 13 |
# File 'lib/mds_file_utils/zip_analyzer.rb', line 10 def initialize(path, original_filename=path) @path = path @original_filename = original_filename end |
Instance Method Details
#file_list ⇒ Object
32 33 34 |
# File 'lib/mds_file_utils/zip_analyzer.rb', line 32 def file_list @files ||= UnzipmeUnzipper.new(@path).file_list end |
#file_size ⇒ Object
44 45 46 |
# File 'lib/mds_file_utils/zip_analyzer.rb', line 44 def file_size File.size(@path) end |
#has_valid_extension? ⇒ Boolean
22 23 24 25 |
# File 'lib/mds_file_utils/zip_analyzer.rb', line 22 def has_valid_extension? return false if @original_filename.blank? @original_filename =~ EXTENSION_REGEX end |
#is_composite? ⇒ Boolean
27 28 29 30 |
# File 'lib/mds_file_utils/zip_analyzer.rb', line 27 def is_composite? return false unless valid_zip? file_list.count { | file | file =~ EXTENSION_REGEX } > 0 end |
#non_mds_data_in_composite? ⇒ Boolean
36 37 38 |
# File 'lib/mds_file_utils/zip_analyzer.rb', line 36 def non_mds_data_in_composite? file_list.count { | entry | !( entry =~ VALID_COMPOSITE_CONTENTS_REGEX) } > 0 end |
#too_big_for_mds? ⇒ Boolean
40 41 42 |
# File 'lib/mds_file_utils/zip_analyzer.rb', line 40 def too_big_for_mds? file_size > MAX_MDS_FILE_SIZE && !is_composite? end |
#valid_zip? ⇒ Boolean
15 16 17 18 19 20 |
# File 'lib/mds_file_utils/zip_analyzer.rb', line 15 def valid_zip? return false if @path.blank? return false unless File.exists?(@path) return false unless has_valid_extension? UnzipmeValidator.new(@path).valid_zip? end |