How to parse CSS

s =<<EOF
  #wrap>header{
    background-color: rgba(200,200,200,0.1);
    border-top: 1px solid rgba(100,150,100,0.4);
    border-bottom: 1px solid rgba(100,150,100,0.4);
    overflow: hidden;
    margin: 0.3em 0.1em 1.5em 0.1em; padding: 0.3em 0.1em;
  }

  #wrap>header>nav:first-child>ul{
    background-color: transparent;
    list-style-type: none;
    margin: 0.2em; padding: 0.3em;
  }
EOF

a = s.split(/}/)[0..-2].map do |entry|

  raw_selector,raw_styles = entry.split(/{/,2)

  h = raw_styles.split(/;/)[0..-2].inject({}) do |r, x| 
    k, v = x.split(/:/,2).map(&:strip)
    r.merge(k.to_sym => v)
  end

  [raw_selector.split(/,\s*/).map(&:strip), h]
end