Class: Hybridge::Batch::Ingest
- Inherits:
-
Object
- Object
- Hybridge::Batch::Ingest
- Defined in:
- lib/hybridge/batch/ingest.rb
Instance Method Summary collapse
-
#initialize(file, collection_id, current_user) ⇒ Ingest
constructor
A new instance of Ingest.
- #load! ⇒ Object
- #processed! ⇒ Object
- #processed? ⇒ Boolean
- #processing! ⇒ Object
- #processing? ⇒ Boolean
- #staged? ⇒ Boolean
Constructor Details
#initialize(file, collection_id, current_user) ⇒ Ingest
Returns a new instance of Ingest.
5 6 7 8 9 10 |
# File 'lib/hybridge/batch/ingest.rb', line 5 def initialize(file, collection_id, current_user) @file = file @collection_id = collection_id @current_user = current_user load! end |
Instance Method Details
#load! ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hybridge/batch/ingest.rb', line 12 def load! return unless staged? || processing? processing! @works = [] @files = {} good_work = false @csv = CSV.parse(File.read(@file), headers: true, encoding: 'utf-8').map(&:to_hash) @csv.each do |row| type = row.first.last if type.nil? good_work = false next elsif Hyrax.config.registered_curation_concern_types.include? type good_work = true row.delete("Filename") @works << row @files[@works.length] = [] elsif type.include? "File" if good_work row.delete("Object Type") @files[@works.length] << row end else good_work = false = "Unknown work type '#{type}'" Hyrax::MessengerService.deliver(User.batch_user, @current_user, , "HyBridge Warning: Unknown work type") end end @works.each_with_index do |work, index| Entry.new(work, @files[index+1], @collection_id, @current_user, File.dirname(@file)) end processed! end |
#processed! ⇒ Object
56 57 58 59 60 |
# File 'lib/hybridge/batch/ingest.rb', line 56 def processed! new_file = Pathname(@file).sub_ext '' + ".processed" File.rename(@file, new_file) @file = new_file end |
#processed? ⇒ Boolean
66 67 68 |
# File 'lib/hybridge/batch/ingest.rb', line 66 def processed? File.file?(Pathname(@file).sub_ext '' + ".processed") end |
#processing! ⇒ Object
50 51 52 53 54 |
# File 'lib/hybridge/batch/ingest.rb', line 50 def processing! new_file = Pathname(@file).sub_ext '' + ".processing" File.rename(@file, new_file) unless File.file?(new_file) @file = new_file end |
#processing? ⇒ Boolean
62 63 64 |
# File 'lib/hybridge/batch/ingest.rb', line 62 def processing? File.file?(Pathname(@file).sub_ext '' + ".processing") end |
#staged? ⇒ Boolean
70 71 72 |
# File 'lib/hybridge/batch/ingest.rb', line 70 def staged? File.file?(Pathname(@file).sub_ext '' + ".staged") end |