Class: Dommy::Internal::SelectorAST::ComplexSelector

Inherits:
Struct
  • Object
show all
Defined in:
lib/dommy/internal/selector_ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#partsObject

Returns the value of attribute parts

Returns:

  • (Object)

    the current value of parts



29
30
31
# File 'lib/dommy/internal/selector_ast.rb', line 29

def parts
  @parts
end

Instance Method Details

#pseudo_elementObject



32
33
34
# File 'lib/dommy/internal/selector_ast.rb', line 32

def pseudo_element
  rightmost&.pseudo_element
end

#pseudo_element?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/dommy/internal/selector_ast.rb', line 36

def pseudo_element?
  !pseudo_element.nil?
end

#rightmostObject



30
# File 'lib/dommy/internal/selector_ast.rb', line 30

def rightmost = parts.last&.compound

#specificityObject



49
50
51
# File 'lib/dommy/internal/selector_ast.rb', line 49

def specificity
  parts.reduce(ZERO) { |sum, part| sum + part.compound.specificity }
end

#without_pseudo_elementObject



40
41
42
43
44
45
46
47
# File 'lib/dommy/internal/selector_ast.rb', line 40

def without_pseudo_element
  return self unless pseudo_element?

  duped = parts.map { |part| Part.new(part.combinator, part.compound) }
  last = duped.last
  last.compound = last.compound.without_pseudo_element
  self.class.new(duped)
end