class Crimp
Public Class Methods
annotate(obj)
click to toggle source
# 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)
click to toggle source
# File lib/crimp.rb, line 13 def notation(obj) annotate(obj).flatten.join end
signature(obj)
click to toggle source
# File lib/crimp.rb, line 9 def signature(obj) Digest::MD5.hexdigest(notation(obj)) end
Private Class Methods
coerce(obj)
click to toggle source
# File lib/crimp.rb, line 44 def coerce(obj) case obj when Symbol then obj.to_s when Set then obj.to_a else obj end end
sort(coll)
click to toggle source
# File lib/crimp.rb, line 40 def sort(coll) coll.deep_sort_by { |obj| obj.to_s }.map { |obj| annotate(obj) } end