Class: Roadie::Selector Private
- Inherits:
-
Object
- Object
- Roadie::Selector
- 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
- #==(other) ⇒ Object private
-
#initialize(selector, specificity = nil) ⇒ Selector
constructor
private
A new instance of Selector.
-
#inlinable? ⇒ Boolean
private
Returns whenever or not a selector can be inlined.
- #inspect ⇒ Object private
-
#specificity ⇒ Object
private
Returns the specificity of the selector, calculating it if needed.
- #to_s ⇒ Object private
- #to_str ⇒ Object private
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.
21 22 23 24 |
# File 'lib/roadie/selector.rb', line 21 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.
54 55 56 57 58 59 60 |
# File 'lib/roadie/selector.rb', line 54 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.
36 37 38 |
# File 'lib/roadie/selector.rb', line 36 def inlinable? !(pseudo_element? || at_rule? || pseudo_function?) end |
#inspect ⇒ 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.
48 49 50 |
# File 'lib/roadie/selector.rb', line 48 def inspect selector.inspect end |
#specificity ⇒ 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.
Returns the specificity of the selector, calculating it if needed.
27 28 29 |
# File 'lib/roadie/selector.rb', line 27 def specificity @specificity ||= CssParser.calculate_specificity selector end |
#to_s ⇒ 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.
40 41 42 |
# File 'lib/roadie/selector.rb', line 40 def to_s selector end |
#to_str ⇒ 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.
44 45 46 |
# File 'lib/roadie/selector.rb', line 44 def to_str to_s end |