Sha256: f039fbf75985ce8a78493822194a2a15c89a6439e4ade70c2a1696504ec58459

Contents?: true

Size: 511 Bytes

Versions: 14

Compression:

Stored size: 511 Bytes

Contents

class String
  def normalize_attribute
    self.gsub(/^.*::/, "").
         gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
         gsub(/([a-z\d])([A-Z])/,'\1_\2').
         downcase
  end
end

class Hash
  def normalize
    h = {}
    self.each_pair do |k,v|
      attr = k.to_s.normalize_attribute
      case v
        when Hash
          h[attr] = v.normalize
        when Array
          h[attr] = v.map { |o| o.kind_of?(Hash) ? o.normalize : o }
        else
          h[attr] = v
      end
    end
    h
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
grooveshark-0.2.11 lib/grooveshark/utils.rb
grooveshark-0.2.10 lib/grooveshark/utils.rb
grooveshark-0.2.9 lib/grooveshark/utils.rb
grooveshark-0.2.8.2 lib/grooveshark/utils.rb
grooveshark-0.2.8.1 lib/grooveshark/utils.rb
grooveshark-0.2.8 lib/grooveshark/utils.rb
grooveshark-0.2.7 lib/grooveshark/utils.rb
grooveshark-0.2.6 lib/grooveshark/utils.rb
grooveshark-0.2.5 lib/grooveshark/utils.rb
grooveshark-0.2.4 lib/grooveshark/utils.rb
grooveshark-0.2.3 lib/grooveshark/utils.rb
grooveshark-0.2.2 lib/grooveshark/utils.rb
grooveshark-0.2.1 lib/grooveshark/utils.rb
grooveshark-0.2.0 lib/grooveshark/utils.rb