Class: Cataract::ConditionalGroup

Inherits:
Struct
  • Object
show all
Defined in:
lib/cataract/conditional_group.rb

Overview

ConditionalGroup represents a CSS "conditional group" at-rule wrapper - @supports, @layer, @container, or @scope.

Like MediaQuery, these are stored in the Stylesheet and referenced by Rules/AtRules via conditional_group_id, so the rules they wrap stay flat and queryable in Stylesheet#rules while the wrapper's own name/condition (and nesting inside other conditional groups, via parent_id) survive for round-trip serialization. Cataract never evaluates the condition/name (no feature-query or container-query matching) - it's kept as opaque text.

Examples:

Access conditional-group properties

group = ConditionalGroup.new(0, :supports, nil, '(display: grid)', nil)
group.id #=> 0
group.type #=> :supports
group.condition #=> "(display: grid)"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#conditionString?

Opaque condition/prelude text (feature query, container query, scope root/limit), nil if none

Returns:

  • (String, nil)

    the current value of condition



26
27
28
# File 'lib/cataract/conditional_group.rb', line 26

def condition
  @condition
end

#idInteger

Unique identifier for this conditional group within the stylesheet

Returns:

  • (Integer)

    the current value of id



26
27
28
# File 'lib/cataract/conditional_group.rb', line 26

def id
  @id
end

#nameString?

Named form (e.g. @layer utilities, @container sidebar), nil if unnamed

Returns:

  • (String, nil)

    the current value of name



26
27
28
# File 'lib/cataract/conditional_group.rb', line 26

def name
  @name
end

#parent_idInteger?

Id of the enclosing ConditionalGroup, or nil if not nested inside another one

Returns:

  • (Integer, nil)

    the current value of parent_id



26
27
28
# File 'lib/cataract/conditional_group.rb', line 26

def parent_id
  @parent_id
end

#typeSymbol

At-rule kind (:supports, :layer, :container, :scope)

Returns:

  • (Symbol)

    the current value of type



26
27
28
# File 'lib/cataract/conditional_group.rb', line 26

def type
  @type
end

Class Method Details

.make(id:, type:, name: nil, condition: nil, parent_id: nil) ⇒ ConditionalGroup

Create a ConditionalGroup with keyword arguments for readability.

Examples:

ConditionalGroup.make(id: 0, type: :supports, condition: '(display: grid)')

Parameters:

  • id (Integer)

    Unique ID for this conditional group

  • type (Symbol)

    At-rule kind (:supports, :layer, :container, :scope)

  • name (String, nil) (defaults to: nil)

    Named form, if any

  • condition (String, nil) (defaults to: nil)

    Opaque condition/prelude text, if any

  • parent_id (Integer, nil) (defaults to: nil)

    Enclosing ConditionalGroup's id, if nested

Returns:



38
39
40
# File 'lib/cataract/conditional_group.rb', line 38

def self.make(id:, type:, name: nil, condition: nil, parent_id: nil)
  new(id, type, name, condition, parent_id)
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Compare conditional groups for equality based on type, name, condition, and nesting. IDs are not considered since they're internal identifiers.

Parameters:

  • other (Object)

    Object to compare with

Returns:

  • (Boolean)

    true if conditional groups match



47
48
49
50
51
52
53
54
# File 'lib/cataract/conditional_group.rb', line 47

def ==(other)
  case other
  when ConditionalGroup
    type == other.type && name == other.name && condition == other.condition
  else
    false
  end
end

#hashInteger

Generate hash code for this conditional group.

Returns:

  • (Integer)

    hash code



60
61
62
# File 'lib/cataract/conditional_group.rb', line 60

def hash
  [self.class, type, name, condition].hash
end

#inspectString

Get detailed inspection string.

Returns:

  • (String)

    Inspection string



67
68
69
70
# File 'lib/cataract/conditional_group.rb', line 67

def inspect
  "#<ConditionalGroup id=#{id} type=#{type.inspect} name=#{name.inspect} " \
    "condition=#{condition.inspect} parent_id=#{parent_id.inspect}>"
end