Class: Roadie::Selector Private

Inherits:
Object
  • Object
show all
Defined in:
lib/roadie/selector.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A selector is a domain object for a CSS selector, such as:

body
a:hover
input::placeholder
p:nth-of-child(4n+1) .important a img

“Selectors” such as “strong, em” are actually two selectors and should be represented as two instances of this class.

This class can also calculate specificity for the selector and answer a few questions about them.

Selectors can be coerced into Strings, so they should be transparent to use anywhere a String is expected.

Instance Method Summary collapse

Constructor Details

#initialize(selector, specificity = nil) ⇒ Selector

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Selector.



19
20
21
22
# File 'lib/roadie/selector.rb', line 19

def initialize(selector, specificity = nil)
  @selector = selector.to_s.strip
  @specificity = specificity
end

Instance Method Details

#==(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Roadie::Selectors are equal to other Roadie::Selectors if, and only if, their string representations are equal.



44
45
46
47
48
49
50
# File 'lib/roadie/selector.rb', line 44

def ==(other)
  if other.is_a?(self.class)
    other.selector == selector
  else
    super
  end
end

#inlinable?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whenever or not a selector can be inlined. It’s impossible to inline properties that applies to a pseudo element (like ::placeholder, ::before) or a pseudo function (like :active).

We cannot inline styles that appear inside “@” constructs, like @keyframes.

Returns:

  • (Boolean)


34
35
36
# File 'lib/roadie/selector.rb', line 34

def inlinable?
  !(pseudo_element? || at_rule? || pseudo_function?)
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
# File 'lib/roadie/selector.rb', line 40

def inspect() selector.inspect end

#specificityObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the specificity of the selector, calculating it if needed.



25
26
27
# File 'lib/roadie/selector.rb', line 25

def specificity
  @specificity ||= CssParser.calculate_specificity selector
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
# File 'lib/roadie/selector.rb', line 38

def to_s() selector end

#to_strObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
# File 'lib/roadie/selector.rb', line 39

def to_str() to_s end