Sha256: 1a6e67b9bfe8981a15c850b1eaf3d39adacdde888e9ccde81c6f30f837b5eb21

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

require 'nokogiri'
require 'active_support'

module LyberCore
  module Utils
    class ChecksumValidate
      #Code here

      def self.compare_hashes(hash1, hash2)
           return (hash1 == hash2)
      end

      def self.get_hash_differences(hash1, hash2)
         return hash1.diff(hash2)
      end

      def self.md5_hash_from_md5sum(md5sum)
        checksum_hash = {}
        md5sum.each do |line|
          line.chomp!
          digest,filename = line.split(/[ *]{2}/)
          checksum_hash[filename] = digest.downcase
        end
        return checksum_hash
      end

      def self.md5_hash_from_mets(mets)
        mets_checksum_hash = {}
        doc = Nokogiri::XML(mets)
        doc.xpath('/mets:mets/mets:fileSec//mets:file', {'mets' => 'http://www.loc.gov/METS/'}).each do |filenode|
           digest = filenode.attribute('CHECKSUM')
           if (digest)
             flocat = filenode.xpath('mets:FLocat', {'mets' => 'http://www.loc.gov/METS/'}).first
             if (flocat)
               filename = flocat.attribute_with_ns('href', 'http://www.w3.org/1999/xlink')
               if (filename)
                 mets_checksum_hash[filename.text] = digest.text.downcase
               end
             end
           end
        end
        return mets_checksum_hash
      end

      def self.md5_hash_from_content_metadata(content_md)
        content_md_checksum_hash = {}
        doc = Nokogiri::XML(content_md)
        doc.xpath('/contentMetadata/resource[@type="page"]/file').each do |filenode|
           filename = filenode.attribute('id')
           if (filename)
             md5_element = filenode.xpath('checksum[@type="MD5"]').first
             if (md5_element)
               digest = md5_element.text
               if (digest)
                 content_md_checksum_hash[filename.text] = digest.downcase
               end
             end
           end
        end
        return content_md_checksum_hash

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lyber-core-1.3.0 lib/lyber_core/utils/checksum_validate.rb