Class: CSS::Selectors::Specificity
- Inherits:
-
Data
- Object
- Data
- CSS::Selectors::Specificity
- Includes:
- Comparable
- Defined in:
- lib/css/selectors/specificity.rb
Overview
Selectors ยง16 specificity tuple โ(a, b, c)`.
a = id selectors
b = class / attribute / pseudo-class selectors
c = type / pseudo-element selectors
Constant Summary collapse
- ZERO =
Specificity.new(a: 0, b: 0, c: 0).freeze
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
-
#c ⇒ Object
readonly
Returns the value of attribute c.
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#<=>(other) ⇒ Object
Avoids the per-call allocation of two 3-element arrays โ this comparison runs many times in the cascade-sort hot path.
- #to_s ⇒ Object
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a
7 8 9 |
# File 'lib/css/selectors/specificity.rb', line 7 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b
7 8 9 |
# File 'lib/css/selectors/specificity.rb', line 7 def b @b end |
#c ⇒ Object (readonly)
Returns the value of attribute c
7 8 9 |
# File 'lib/css/selectors/specificity.rb', line 7 def c @c end |
Instance Method Details
#+(other) ⇒ Object
24 25 26 |
# File 'lib/css/selectors/specificity.rb', line 24 def +(other) Specificity.new(a: a + other.a, b: b + other.b, c: c + other.c) end |
#<=>(other) ⇒ Object
Avoids the per-call allocation of two 3-element arrays โ this comparison runs many times in the cascade-sort hot path.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/css/selectors/specificity.rb', line 12 def <=>(other) return nil unless other.is_a?(Specificity) d = a - other.a return d unless d.zero? d = b - other.b return d unless d.zero? c - other.c end |
#to_s ⇒ Object
28 |
# File 'lib/css/selectors/specificity.rb', line 28 def to_s = "#{a},#{b},#{c}" |