Module: Treequel::Normalization
- Included in:
- Model, Schema::AttributeType, Schema::Table
- Defined in:
- lib/treequel/mixins.rb
Overview
A collection of key-normalization functions for various artifacts in LDAP like attribute names, objectclass OIDs, etc.
Class Method Summary collapse
-
.normalize_hash(hash) ⇒ Object
Return a copy of
hashwith all of its keys normalized by #normalize_key. -
.normalize_key(key) ⇒ Object
Normalize the given key, returning a downcased Symbol stripped of any invalid characters, and with ‘-’ characters converted to ‘_’.
Class Method Details
.normalize_hash(hash) ⇒ Object
Return a copy of hash with all of its keys normalized by #normalize_key.
135 136 137 138 139 140 141 142 143 |
# File 'lib/treequel/mixins.rb', line 135 def normalize_hash( hash ) hash = hash.dup hash.keys.each do |key| nkey = normalize_key( key ) hash[ nkey ] = hash.delete( key ) if key != nkey end return hash end |
.normalize_key(key) ⇒ Object
Normalize the given key, returning a downcased Symbol stripped of any invalid characters, and with ‘-’ characters converted to ‘_’.
126 127 128 129 130 131 132 |
# File 'lib/treequel/mixins.rb', line 126 def normalize_key( key ) return key if key.to_s =~ Treequel::Constants::Patterns::NUMERICOID return key.to_s.downcase. gsub( /[^[:alnum:]\-_]/, '' ). gsub( '-', '_' ). to_sym end |