Class: Cataract::AtRule
- Inherits:
-
Object
- Object
- Cataract::AtRule
- Defined in:
- lib/cataract/at_rule.rb
Overview
Represents a CSS at-rule like @keyframes, @font-face, @supports, etc.
AtRule is a C struct defined as: ‘Struct.new(:id, :selector, :content, :specificity)`
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).
-
#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 by their attributes rather than object identity.
-
#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
35 36 37 |
# File 'lib/cataract/at_rule.rb', line 35 def content @content end |
#id ⇒ Integer
The at-rule’s position in the stylesheet (0-indexed)
35 36 37 |
# File 'lib/cataract/at_rule.rb', line 35 def id @id end |
#selector ⇒ String
The at-rule identifier (e.g., “@keyframes fade”, “@font-face”)
35 36 37 |
# File 'lib/cataract/at_rule.rb', line 35 def selector @selector end |
#specificity ⇒ nil
Always nil for at-rules (they don’t have CSS specificity)
35 36 37 |
# File 'lib/cataract/at_rule.rb', line 35 def specificity @specificity end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare at-rules by their attributes rather than object identity.
Two at-rules are equal if they have the same id, selector, and content.
88 89 90 91 92 93 94 |
# File 'lib/cataract/at_rule.rb', line 88 def ==(other) return false unless other.is_a?(AtRule) id == other.id && selector == other.selector && content == other.content end |
#at_rule? ⇒ Boolean
Check if this is an at-rule.
46 47 48 |
# File 'lib/cataract/at_rule.rb', line 46 def at_rule? true end |
#at_rule_type?(type) ⇒ Boolean
Check if this is a specific at-rule type.
60 61 62 63 |
# File 'lib/cataract/at_rule.rb', line 60 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.
78 79 80 |
# File 'lib/cataract/at_rule.rb', line 78 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.
70 71 72 |
# File 'lib/cataract/at_rule.rb', line 70 def has_property?(_property, _value = nil) false end |
#selector? ⇒ Boolean
Check if this is a selector-based rule (vs an at-rule like @keyframes).
39 40 41 |
# File 'lib/cataract/at_rule.rb', line 39 def selector? false end |