Thingfish::

Normalization

module

A collection of functions for dealing with object IDs.

Public Instance Methods

anchor
make_object_id()

Generate a new object ID.

# File lib/thingfish/mixins.rb, line 18
def make_object_id
        return normalize_oid( SecureRandom.uuid )
end
anchor
normalize_key( key )

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
anchor
normalize_keys( collection )

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
anchor
normalize_oid( oid )

Normalize the given oid.

# File lib/thingfish/mixins.rb, line 24
def normalize_oid( oid )
        return oid.to_s.downcase
end