A collection of functions for dealing with object IDs.
Generate a new object ID.
# File lib/thingfish/mixins.rb, line 18
def make_object_id
return normalize_oid( SecureRandom.uuid )
end
Return a normalized copy of key
.
# File lib/thingfish/mixins.rb, line 46
def normalize_key( key )
return key.to_s.downcase.gsub( /[^\w:]+/, '_' )
end
Return a copy of the given collection
after being normalized.
# File lib/thingfish/mixins.rb, line 30
def normalize_keys( collection )
if collection.respond_to?( :keys )
return collection.each_with_object({}) do |(key,val),new_hash|
n_key = normalize_key( key )
new_hash[ n_key ] = val
end
elsif collection.respond_to?( :map )
return collection.map {|key| normalize_key(key) }
end
return nil
end
Normalize the given oid
.
# File lib/thingfish/mixins.rb, line 24
def normalize_oid( oid )
return oid.to_s.downcase
end