Class: FedoraMigrate::MigrationReport

Inherits:
Object
  • Object
show all
Defined in:
lib/fedora_migrate/migration_report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report = nil) ⇒ MigrationReport

Returns a new instance of MigrationReport.



6
7
8
# File 'lib/fedora_migrate/migration_report.rb', line 6

def initialize report=nil
  @results = report.nil? ? Hash.new : JSON.parse(File.read(report))
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



4
5
6
# File 'lib/fedora_migrate/migration_report.rb', line 4

def results
  @results
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/fedora_migrate/migration_report.rb', line 10

def empty?
  results.empty?
end

#failed_objectsObject



14
15
16
# File 'lib/fedora_migrate/migration_report.rb', line 14

def failed_objects
  results.keys.map { |k| k unless results[k]["status"] }.compact
end

#failuresObject



18
19
20
# File 'lib/fedora_migrate/migration_report.rb', line 18

def failures
  failed_objects.count
end

#report_failures(output = String.new) ⇒ Object



26
27
28
29
30
31
# File 'lib/fedora_migrate/migration_report.rb', line 26

def report_failures output = String.new
  failed_objects.each do |k|
    output << "#{k}:\n\tobject: #{results[k]["object"]}\n\trelationships: #{results[k]["relationships"]}\n\n"
  end
  output
end

#save(path = nil) ⇒ Object



33
34
35
36
37
# File 'lib/fedora_migrate/migration_report.rb', line 33

def save path=nil
  json = JSON.load(results.to_json)
  file = path.nil? ? "report.json" : File.join(path,"report.json")
  File.write(file, JSON.pretty_generate(json))
end

#total_objectsObject



22
23
24
# File 'lib/fedora_migrate/migration_report.rb', line 22

def total_objects
  results.keys.count
end