Crass is a pure Ruby CSS parser that implements the 2013 draft of the CSS Syntax Level 3 specification. I created it because I needed a good Ruby CSS 3 parser and there wasn't one. Now there is!
Pure Ruby, with no runtime dependencies other than Ruby 1.9.x or higher.
Extremely tolerant of broken or invalid CSS. If a browser can handle it, Crass should be able to handle it too.
Optionally includes comments in the token stream.
Optionally preserves certain CSS hacks, such as the IE "*" hack, which would otherwise be discarded according to CSS3 tokenizing rules.
Capable of serializing the parse tree back to CSS with perfect fidelity, maintaining all original whitespace, comments, and indentation.
gem install crass
Head over to the Crass project page on GitHub for more details, including documentation and examples.