Class: CssCompare::CSS::Component::Supports
- Includes:
- CssCompare::CSS::Component
- Defined in:
- lib/css_compare/css/component/supports.rb
Overview
Represents the @support CSS rule.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the @support directive.
-
#rules ⇒ Hash{String => CssCompare::CSS::Engine}
The assigned rules grouped by the @supports’ conditions.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Checks, whether two @supports rules are equal.
-
#deep_copy(name = @name) ⇒ Supports
Returns a deep copy of this object.
-
#initialize(node, query_list = []) ⇒ Supports
constructor
A new instance of Supports.
-
#merge(other) ⇒ Void
Merges this @supports rule with another one.
-
#to_json ⇒ Hash
Creates the JSON representation of this object.
Methods included from CssCompare::CSS::Component
Methods inherited from Base
Constructor Details
#initialize(node, query_list = []) ⇒ Supports
Returns a new instance of Supports.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/css_compare/css/component/supports.rb', line 29 def initialize(node, query_list = []) @name = node.name @rules = {} condition = node.condition.to_css.gsub(/\s*!important\s*/, '') unless query_list.empty? media_node = media_node([Engine::GLOBAL_QUERY], node.children, node.) node = root_node(media_node, node.) end rules = CssCompare::CSS::Engine.new(node).evaluate(nil, query_list) @rules[condition] = rules end |
Instance Attribute Details
#name ⇒ String (readonly)
The name of the @support directive. Can be browser-prefixed.
14 15 16 |
# File 'lib/css_compare/css/component/supports.rb', line 14 def name @name end |
#rules ⇒ Hash{String => CssCompare::CSS::Engine}
The assigned rules grouped by the @supports’ conditions.
stylesheet. Why not to create a new engine for it?
23 24 25 |
# File 'lib/css_compare/css/component/supports.rb', line 23 def rules @rules end |
Instance Method Details
#==(other) ⇒ Boolean
Checks, whether two @supports rules are equal.
They are only equal, if all of their rules are equal.
49 50 51 |
# File 'lib/css_compare/css/component/supports.rb', line 49 def ==(other) super(@rules, other.rules) end |
#deep_copy(name = @name) ⇒ Supports
Returns a deep copy of this object.
73 74 75 76 77 78 79 |
# File 'lib/css_compare/css/component/supports.rb', line 73 def deep_copy(name = @name) copy = dup copy.name = name copy.rules = {} @rules.each { |k, v| copy.rules[k] = v.deep_copy } copy end |
#merge(other) ⇒ Void
Merges this @supports rule with another one.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/css_compare/css/component/supports.rb', line 57 def merge(other) other.rules.each do |cond, engine| if @rules[cond] merge_selectors(engine.selectors, cond) merge_keyframes(engine.keyframes, cond) merge_namespaces(engine.namespaces, cond) merge_supports(engine.supports, cond) else @rules[cond] = engine end end end |
#to_json ⇒ Hash
Creates the JSON representation of this object.
84 85 86 87 88 89 90 |
# File 'lib/css_compare/css/component/supports.rb', line 84 def to_json json = { :name => @name.to_sym, :rules => {} } @rules.inject(json[:rules]) do |result, (k, v)| result.update(k => v.to_json) end json end |