Sha256: ce8e03f651b53e180c59e539fd8b39bec7a8d4462eb5185cd9a8ca881b0550c2

Contents?: true

Size: 1.36 KB

Versions: 14

Compression:

Stored size: 1.36 KB

Contents

module Roadie
  # @api private
  # Domain object for a CSS property such as "color: red !important".
  #
  # @attr_reader [String] property name of the property (such as "font-size").
  # @attr_reader [String] value value of the property (such as "5px solid green").
  # @attr_reader [Boolean] important if the property is "!important".
  # @attr_reader [Integer] specificity specificity of parent {Selector}. Used to compare/sort.
  class StyleProperty
    include Comparable

    attr_reader :value, :important, :specificity

    # @todo Rename #property to #name
    attr_reader :property

    def initialize(property, value, important, specificity)
      @property = property
      @value = value
      @important = important
      @specificity = specificity
    end

    def important?
      @important
    end

    # Compare another {StyleProperty}. Important styles are "greater than"
    # non-important ones; otherwise the specificity declares order.
    def <=>(other)
      if important == other.important
        specificity <=> other.specificity
      else
        important ? 1 : -1
      end
    end

    def to_s
      [property, value_with_important].join(':')
    end

    def inspect
      "#{to_s} (#{specificity})"
    end

    private
    def value_with_important
      if important
        "#{value} !important"
      else
        value
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
roadie-3.5.1 lib/roadie/style_property.rb
roadie-3.5.0 lib/roadie/style_property.rb
roadie-3.4.0 lib/roadie/style_property.rb
roadie-3.3.0 lib/roadie/style_property.rb
roadie-3.2.2 lib/roadie/style_property.rb
roadie-3.2.1 lib/roadie/style_property.rb
roadie-3.2.0 lib/roadie/style_property.rb
roadie-3.1.1 lib/roadie/style_property.rb
roadie-3.1.0 lib/roadie/style_property.rb
roadie-3.1.0.rc1 lib/roadie/style_property.rb
roadie-3.0.5 lib/roadie/style_property.rb
roadie-3.0.4 lib/roadie/style_property.rb
roadie-3.0.3 lib/roadie/style_property.rb
roadie-3.0.2 lib/roadie/style_property.rb