Class: Crimp

Inherits:
Object
  • Object
show all
Defined in:
lib/crimp.rb

Class Method Summary collapse

Class Method Details

.annotate(obj) ⇒ Object



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

def annotate(obj)
  obj = coerce(obj)

  case obj
  when String
    [obj, 'S']
  when Numeric
    [obj, 'N']
  when TrueClass, FalseClass
    [obj, 'B']
  when NilClass
    [nil, '_']
  when Array
    [sort(obj), 'A']
  when Hash
    [sort(obj), 'H']
  else
    raise TypeError, "Expected a (String|Number|Boolean|Nil|Hash|Array), Got #{obj.class}."
  end
end

.notation(obj) ⇒ Object



13
14
15
# File 'lib/crimp.rb', line 13

def notation(obj)
  annotate(obj).flatten.join
end

.signature(obj) ⇒ Object



9
10
11
# File 'lib/crimp.rb', line 9

def signature(obj)
  Digest::MD5.hexdigest(notation(obj))
end