Module: MDQT::Client::IdentifierUtils

Defined in:
lib/mdqt/client/identifier_utils.rb

Class Method Summary collapse

Class Method Details

.correct_fish_transformed(lazy) ⇒ Object



41
42
43
# File 'lib/mdqt/client/identifier_utils.rb', line 41

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

.correct_lazy_transformed(lazy) ⇒ Object



37
38
39
# File 'lib/mdqt/client/identifier_utils.rb', line 37

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

.fish_transformed?(string) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# 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) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# 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) ⇒ Object



19
20
21
22
23
# 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) ⇒ Object



15
16
17
# File 'lib/mdqt/client/identifier_utils.rb', line 15

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

.uri_to_sha1(uri) ⇒ Object



10
11
12
13
# 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) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/mdqt/client/identifier_utils.rb', line 25

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