Class: Cataract::AtRule
- Inherits:
-
Struct
- Object
- Struct
- Cataract::AtRule
- Defined in:
- lib/cataract/at_rule.rb,
lib/cataract/at_rule.rb
Overview
At-rules define CSS resources or control structures rather than selecting elements.
Unlike regular rules, they don't have CSS specificity and are filtered out when
using select(&:selector?).
The content field varies by at-rule type:
@keyframes: Array of Rule (keyframe percentage blocks like "0%", "100%")@font-face: Array of Declaration (font property declarations)@supports: Array of Rule (conditional rules)
Instance Attribute Summary collapse
-
#content ⇒ Array<Rule>, Array<Declaration>
Nested rules or declarations.
-
#id ⇒ Integer
The at-rule's position in the stylesheet (0-indexed).
-
#media_query_id ⇒ Integer?
ID of MediaQuery if inside @media block, nil otherwise.
-
#selector ⇒ String
The at-rule identifier (e.g., "@keyframes fade", "@font-face").
-
#specificity ⇒ nil
Always nil for at-rules (they don't have CSS specificity).
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare at-rules for logical equality based on CSS semantics.
-
#at_rule? ⇒ Boolean
Check if this is an at-rule.
-
#at_rule_type?(type) ⇒ Boolean
Check if this is a specific at-rule type.
-
#has_important?(_property = nil) ⇒ Boolean
Check if this at-rule has any !important declarations.
-
#has_property?(_property, _value = nil) ⇒ Boolean
Check if this at-rule has a declaration with the specified property.
-
#selector? ⇒ Boolean
Check if this is a selector-based rule (vs an at-rule like @keyframes).
Instance Attribute Details
#content ⇒ Array<Rule>, Array<Declaration>
Nested rules or declarations
32 33 34 |
# File 'lib/cataract/at_rule.rb', line 32 def content @content end |
#id ⇒ Integer
The at-rule's position in the stylesheet (0-indexed)
32 33 34 |
# File 'lib/cataract/at_rule.rb', line 32 def id @id end |
#media_query_id ⇒ Integer?
ID of MediaQuery if inside @media block, nil otherwise
32 33 34 |
# File 'lib/cataract/at_rule.rb', line 32 def media_query_id @media_query_id end |
#selector ⇒ String
The at-rule identifier (e.g., "@keyframes fade", "@font-face")
32 33 34 |
# File 'lib/cataract/at_rule.rb', line 32 def selector @selector end |
#specificity ⇒ nil
Always nil for at-rules (they don't have CSS specificity)
32 33 34 |
# File 'lib/cataract/at_rule.rb', line 32 def specificity @specificity end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare at-rules for logical equality based on CSS semantics.
Two at-rules are equal if they have the same selector and content. Internal implementation details (id) are not considered since they don't affect the CSS semantics.
89 90 91 92 93 94 |
# File 'lib/cataract/at_rule.rb', line 89 def ==(other) return false unless other.is_a?(AtRule) selector == other.selector && content == other.content end |
#at_rule? ⇒ Boolean
Check if this is an at-rule.
45 46 47 |
# File 'lib/cataract/at_rule.rb', line 45 def at_rule? true end |
#at_rule_type?(type) ⇒ Boolean
Check if this is a specific at-rule type.
59 60 61 62 |
# File 'lib/cataract/at_rule.rb', line 59 def at_rule_type?(type) type_str = "@#{type.to_s.tr('_', '-')}" selector.start_with?(type_str) end |
#has_important?(_property = nil) ⇒ Boolean
Check if this at-rule has any !important declarations.
77 78 79 |
# File 'lib/cataract/at_rule.rb', line 77 def has_important?(_property = nil) false end |
#has_property?(_property, _value = nil) ⇒ Boolean
Check if this at-rule has a declaration with the specified property.
69 70 71 |
# File 'lib/cataract/at_rule.rb', line 69 def has_property?(_property, _value = nil) false end |
#selector? ⇒ Boolean
Check if this is a selector-based rule (vs an at-rule like @keyframes).
38 39 40 |
# File 'lib/cataract/at_rule.rb', line 38 def selector? false end |