module MDQT::Client::IdentifierUtils
Public Class Methods
correct_fish_transformed(lazy)
click to toggle source
# File lib/mdqt/client/identifier_utils.rb, line 41 def correct_fish_transformed(lazy) lazy.gsub("sha1", "{sha1}").downcase end
correct_lazy_transformed(lazy)
click to toggle source
# File lib/mdqt/client/identifier_utils.rb, line 37 def correct_lazy_transformed(lazy) lazy.gsub("[sha1]", "{sha1}").downcase end
fish_transformed?(string)
click to toggle source
# File lib/mdqt/client/identifier_utils.rb, line 33 def fish_transformed?(string) (string =~ /^sha1[0-9a-f]{40}$/i).nil? ? false : true end
lazy_transformed?(string)
click to toggle source
# File lib/mdqt/client/identifier_utils.rb, line 29 def lazy_transformed?(string) (string =~ /^[\[]sha1[\]][0-9a-f]{40}$/i).nil? ? false : true end
normalize_to_sha1(identifier)
click to toggle source
# File lib/mdqt/client/identifier_utils.rb, line 19 def normalize_to_sha1(identifier) identifier.start_with?("{sha1}") ? identifier.gsub("{sha1}", "") : uri_to_sha1(identifier) end
transform_uri(uri)
click to toggle source
# File lib/mdqt/client/identifier_utils.rb, line 15 def transform_uri(uri) "{sha1}#{uri_to_sha1(uri)}" end
uri_to_sha1(uri)
click to toggle source
# File lib/mdqt/client/identifier_utils.rb, line 10 def uri_to_sha1(uri) raise "An empty string cannot be transformed" if uri.empty? Digest::SHA1.hexdigest(uri.to_s.strip) end
valid_transformed?(string)
click to toggle source
# File lib/mdqt/client/identifier_utils.rb, line 25 def valid_transformed?(string) (string =~ /^[{]sha1[}][0-9a-f]{40}$/i).nil? ? false : true end