Module: HashDigest

Defined in:
lib/hash_digest.rb,
lib/hash_digest/version.rb

Constant Summary collapse

VERSION =
"1.1.0"

Class Method Summary collapse

Class Method Details

.as_digest1(obj) ⇒ Object

LEGACY


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hash_digest.rb', line 20

def self.as_digest1(obj)
  ordered_list = case obj
  when ::Hash
    obj.map do |k, v|
      obj[k].to_hash_digest_query k
    end.sort
  when ::Array
    ary = []
    obj.each_with_index do |v, i|
      ary << v.to_hash_digest_query(i)
    end
    ary
  else
    raise ::ArgumentError, "[hash_digest gem] Can only digest Hashes and Arrays, not #{obj.class}"
  end
  ordered_list.join '&'
end

.as_digest2(obj) ⇒ Object

CURRENT


10
11
12
# File 'lib/hash_digest.rb', line 10

def self.as_digest2(obj)
  obj.to_hash_digest_query
end

.digest2(obj) ⇒ Object


14
15
16
# File 'lib/hash_digest.rb', line 14

def self.digest2(obj)
  ::MurmurHash3::V32.str_hash(as_digest2(obj)).to_s 36
end

.hexdigest(obj) ⇒ Object


38
39
40
# File 'lib/hash_digest.rb', line 38

def self.hexdigest(obj)
  ::Digest::MD5.hexdigest as_digest1(obj)
end