Class: Moab::FileInventoryDifference

Inherits:
Manifest
  • Object
show all
Includes:
HappyMapper
Defined in:
lib/moab/file_inventory_difference.rb

Overview

Note:

Copyright © 2012 by The Board of Trustees of the Leland Stanford Junior University. All rights reserved. See LICENSE for details.

Compares two FileInventory instances based primarily on file signatures and secondarily on file pathnames. Although the usual use will be to compare the content of 2 different temporal versions of the same object, it can also be used to verify an inventory document against an inventory harvested from a directory. The report is subdivided into sections for each of the file groups that compose the inventories being compared.

Data Model

Examples:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ FileInventoryDifference

Returns a new instance of FileInventoryDifference


28
29
30
31
# File 'lib/moab/file_inventory_difference.rb', line 28

def initialize(opts={})
  @group_differences = Array.new
  super(opts)
end

Instance Attribute Details

#basisString

Returns Id information from the version inventory used as the basis for comparison

Returns:

  • (String)

    Id information from the version inventory used as the basis for comparison


47
# File 'lib/moab/file_inventory_difference.rb', line 47

attribute :basis, String

#difference_countInteger

Returns the number of differences found between the two inventories that were compared (dynamically calculated)

Returns:

  • (Integer)

    the number of differences found between the two inventories that were compared (dynamically calculated)


39
# File 'lib/moab/file_inventory_difference.rb', line 39

attribute :difference_count, Integer, :tag=> 'differenceCount',:on_save => Proc.new {|i| i.to_s}

#digital_object_idString

Returns The digital object ID (druid)

Returns:

  • (String)

    The digital object ID (druid)


35
# File 'lib/moab/file_inventory_difference.rb', line 35

attribute :digital_object_id, String, :tag => 'objectId'

#group_differencesArray<FileGroupDifference>

Returns The set of data groups comprising the version

Returns:


67
# File 'lib/moab/file_inventory_difference.rb', line 67

has_many :group_differences, FileGroupDifference, :tag => 'fileGroupDifference'

#otherString

Returns Id information about the version inventory compared to the basis

Returns:

  • (String)

    Id information about the version inventory compared to the basis


51
# File 'lib/moab/file_inventory_difference.rb', line 51

attribute :other, String

#report_datetimeString

Returns The datetime at which the report was run

Returns:

  • (String)

    The datetime at which the report was run


55
# File 'lib/moab/file_inventory_difference.rb', line 55

attribute :report_datetime, String, :tag => 'reportDatetime'

Instance Method Details

#common_object_id(basis_inventory, other_inventory) ⇒ String

Returns either the common digitial object ID, or a concatenation of both inventory's IDs

Parameters:

  • basis_inventory (FileInventory)

    The inventory that is the basis of the comparison

  • other_inventory (FileInventory)

    The inventory that is compared against the basis inventory

Returns:

  • (String)

    Returns either the common digitial object ID, or a concatenation of both inventory's IDs


104
105
106
107
108
109
110
# File 'lib/moab/file_inventory_difference.rb', line 104

def common_object_id(basis_inventory, other_inventory)
  if basis_inventory.digital_object_id != other_inventory.digital_object_id
    "#{basis_inventory.digital_object_id.to_s}|#{other_inventory.digital_object_id.to_s}"
  else
    basis_inventory.digital_object_id.to_s
  end
end

#compare(basis_inventory, other_inventory) ⇒ FileInventoryDifference

Returns a report showing the differences, if any, between two inventories

Examples:

Parameters:

  • basis_inventory (FileInventory)

    The inventory that is the basis of the comparison

  • other_inventory (FileInventory)

    The inventory that is compared against the basis inventory

Returns:


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/moab/file_inventory_difference.rb', line 85

def compare(basis_inventory, other_inventory)
  @digital_object_id ||= common_object_id(basis_inventory, other_inventory)
  @basis ||= basis_inventory.data_source
  @other ||= other_inventory.data_source
  @report_datetime = Time.now
  # get a union list of all group_ids present in either inventory
  group_ids = basis_inventory.group_ids | other_inventory.group_ids
  group_ids.each do |group_id|
    # get a pair of groups to compare, creating a empty group if not present in the inventory
    basis_group = basis_inventory.group(group_id) || FileGroup.new(:group_id => group_id)
    other_group = other_inventory.group(group_id) || FileGroup.new(:group_id => group_id)
    @group_differences << FileGroupDifference.new.compare_file_groups(basis_group, other_group)
  end
  self
end

#differences_detailHash

Returns Serializes the data and then filters it to report only the changes

Returns:

  • (Hash)

    Serializes the data and then filters it to report only the changes


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/moab/file_inventory_difference.rb', line 113

def differences_detail
  #return self.summary if difference_count == 0
  inv_diff = self.to_hash
  inv_diff["group_differences"].each_value do |group_diff|
    delete_subsets = []
    group_diff["subsets"].each do |change_type,subset|
      delete_subsets << change_type if change_type == "identical" or subset["count"] == 0
    end
    delete_subsets.each do |change_type|
      group_diff["subsets"].delete(change_type)
      group_diff.delete(change_type) if change_type != "identical"
    end
    group_diff.delete("subsets") if group_diff["subsets"].empty?
  end
  inv_diff
end

#group_difference(group_id) ⇒ FileGroupDifference

Returns The subset of this report for the specified group_id (or nil if not found)

Parameters:

  • group_id (String)

    The identifer of the group to be selected

Returns:

  • (FileGroupDifference)

    The subset of this report for the specified group_id (or nil if not found)


76
77
78
# File 'lib/moab/file_inventory_difference.rb', line 76

def group_difference(group_id)
  @group_differences.find{ |group_difference| group_difference.group_id == group_id}
end

#summary_fieldsArray<String>

Returns The data fields to include in summary reports

Returns:

  • (Array<String>)

    The data fields to include in summary reports


70
71
72
# File 'lib/moab/file_inventory_difference.rb', line 70

def summary_fields
  %w{digital_object_id difference_count basis other report_datetime group_differences}
end