Sha256: 7c3f8e1cd2bf1f4f618d55a3efa2413744a26dc800e95ac070b3da97fadc6a6a

Contents?: true

Size: 640 Bytes

Versions: 5

Compression:

Stored size: 640 Bytes

Contents

require "beautiful-css/rule"

module BeautifulCss
  class RuleParser

    def initialize(str)
      @body = str
    end

    def selectors
      @body.match(/[^{]*/).to_s.split(/,/).map{|s| s.strip}.select{|s| !s.empty? }
    end

    def props
      begin
      p = @body.match(/\{([^}]*)/)[1].split(';').select{|s| !s.strip.empty? }
      p.map{|s| s.strip.split(':') }
      rescue
        []
      end
    end

    def to_rules
      selectors.map do |selector|
        props.map do |prop|
          BeautifulCss::Rule.new(selector, prop[0], prop[1])
        end
      end.flatten
    end

    def body
      @body
    end


  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
beautiful-css-0.0.8 lib/beautiful-css/rule_parser.rb
beautiful-css-0.0.6 lib/beautiful-css/rule_parser.rb
beautiful-css-0.0.5 lib/beautiful-css/rule_parser.rb
beautiful-css-0.0.4 lib/beautiful-css/rule_parser.rb
beautiful-css-0.0.3 lib/beautiful-css/rule_parser.rb