module Thingfish::Normalization
A collection of functions for dealing with object IDs.
Public Instance Methods
make_object_id()
click to toggle source
Generate a new object ID.
# File lib/thingfish/mixins.rb, line 18 def make_object_id return normalize_oid( SecureRandom.uuid ) end
normalize_key( key )
click to toggle source
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
normalize_keys( collection )
click to toggle source
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_oid( oid )
click to toggle source
Normalize the given oid
.
# File lib/thingfish/mixins.rb, line 24 def normalize_oid( oid ) return oid.to_s.downcase end