Sha256: e0100385201e1ebcecca60f6a86011d49fddc006e231651ce6afa35a843e7736

Contents?: true

Size: 1.1 KB

Versions: 16

Compression:

Stored size: 1.1 KB

Contents

module MDQT
  class Client

    module IdentifierUtils

      require 'digest'

      class << self

        def uri_to_sha1(uri)
          raise "An empty string cannot be transformed" if uri.empty?
          Digest::SHA1.hexdigest(uri.to_s.strip)
        end

        def transform_uri(uri)
          "{sha1}#{uri_to_sha1(uri)}"
        end

        def normalize_to_sha1(identifier)
          identifier.start_with?("{sha1}") ?
              identifier.gsub("{sha1}", "") :
              uri_to_sha1(identifier)
        end

        def valid_transformed?(string)
          (string =~ /^[{]sha1[}][0-9a-f]{40}$/i).nil? ? false : true
        end

        def lazy_transformed?(string)
          (string =~ /^[\[]sha1[\]][0-9a-f]{40}$/i).nil? ? false : true
        end

        def fish_transformed?(string)
          (string =~ /^sha1[0-9a-f]{40}$/i).nil? ? false : true
        end

        def correct_lazy_transformed(lazy)
         lazy.gsub("[sha1]", "{sha1}").downcase
        end

        def correct_fish_transformed(lazy)
          lazy.gsub("sha1", "{sha1}").downcase
        end

      end

    end

  end

end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
aaf-mdqt-0.8.8 lib/mdqt/client/identifier_utils.rb
aaf-mdqt-0.8.7 lib/mdqt/client/identifier_utils.rb
aaf-mdqt-0.8.6 lib/mdqt/client/identifier_utils.rb
aaf-mdqt-0.8.5 lib/mdqt/client/identifier_utils.rb
aaf-mdqt-0.8.4 lib/mdqt/client/identifier_utils.rb
aaf-mdqt-0.8.3 lib/mdqt/client/identifier_utils.rb
aaf-mdqt-0.8.2 lib/mdqt/client/identifier_utils.rb
aaf-mdqt-0.8.1 lib/mdqt/client/identifier_utils.rb
aaf-mdqt-0.8.0 lib/mdqt/client/identifier_utils.rb
mdqt-0.8.0 lib/mdqt/client/identifier_utils.rb
mdqt-0.7.0 lib/mdqt/client/identifier_utils.rb
mdqt-0.6.0 lib/mdqt/client/identifier_utils.rb
mdqt-0.5.0 lib/mdqt/client/identifier_utils.rb
mdqt-0.4.0 lib/mdqt/client/identifier_utils.rb
mdqt-0.3.1 lib/mdqt/client/identifier_utils.rb
mdqt-0.3.0 lib/mdqt/client/identifier_utils.rb