Class: Bulkrax::CsvTemplate::FileValidator

Inherits:
Object
  • Object
show all
Defined in:
app/services/bulkrax/csv_template/file_validator.rb

Overview

Validates file references in CSV against zip archive contents

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(csv_data, zip_file = nil, admin_set_id = nil) ⇒ FileValidator

Returns a new instance of FileValidator.



10
11
12
13
14
# File 'app/services/bulkrax/csv_template/file_validator.rb', line 10

def initialize(csv_data, zip_file = nil, admin_set_id = nil)
  @csv_data = csv_data
  @zip_file = zip_file
  @admin_set_id = admin_set_id
end

Instance Attribute Details

#csv_dataObject (readonly)

Returns the value of attribute csv_data.



8
9
10
# File 'app/services/bulkrax/csv_template/file_validator.rb', line 8

def csv_data
  @csv_data
end

#zip_fileObject (readonly)

Returns the value of attribute zip_file.



8
9
10
# File 'app/services/bulkrax/csv_template/file_validator.rb', line 8

def zip_file
  @zip_file
end

Instance Method Details

#count_referencesObject



16
17
18
# File 'app/services/bulkrax/csv_template/file_validator.rb', line 16

def count_references
  @csv_data.count { |item| item[:file].present? }
end

#found_files_countObject



26
27
28
29
30
# File 'app/services/bulkrax/csv_template/file_validator.rb', line 26

def found_files_count
  return 0 unless @zip_file

  (referenced_files & zip_file_list).count
end

#missing_filesObject



20
21
22
23
24
# File 'app/services/bulkrax/csv_template/file_validator.rb', line 20

def missing_files
  return [] unless @zip_file

  referenced_files - zip_file_list
end

#possible_missing_files?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'app/services/bulkrax/csv_template/file_validator.rb', line 36

def possible_missing_files?
  return false unless referenced_files.any?
  return true if @zip_file.blank?

  false
end

#zip_included?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/services/bulkrax/csv_template/file_validator.rb', line 32

def zip_included?
  @zip_file.present?
end