Class: Sass::Selector::AbstractSequence
- Inherits:
-
Object
- Object
- Sass::Selector::AbstractSequence
- Defined in:
- lib/sass/selector/abstract_sequence.rb
Overview
The abstract parent class of the various selector sequence classes.
All subclasses should implement a members
method that returns an array
of object that respond to #line=
and #filename=
, as well as a to_a
method that returns an array of strings and script nodes.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#filename ⇒ String?
The name of the file in which this selector was declared.
-
#line ⇒ Fixnum
The line of the Sass template on which this selector was declared.
Instance Method Summary collapse
- #_specificity(arr) protected
-
#eql?(other) ⇒ Boolean
(also: #==)
Checks equality between this and another object.
-
#has_placeholder? ⇒ Boolean
Whether or not this selector sequence contains a placeholder selector.
-
#hash ⇒ Fixnum
Returns a hash code for this sequence.
-
#specificity ⇒ Fixnum
Returns the specificity of the selector as an integer.
-
#to_s ⇒ String
Converts the selector into a string.
Instance Attribute Details
#filename ⇒ String?
The name of the file in which this selector was declared.
17 18 19 |
# File 'lib/sass/selector/abstract_sequence.rb', line 17
def filename
@filename
end
|
#line ⇒ Fixnum
The line of the Sass template on which this selector was declared.
12 13 14 |
# File 'lib/sass/selector/abstract_sequence.rb', line 12
def line
@line
end
|
Instance Method Details
#_specificity(arr) (protected)
87 88 89 90 91 |
# File 'lib/sass/selector/abstract_sequence.rb', line 87
def _specificity(arr)
spec = 0
arr.map {|m| spec += m.is_a?(String) ? 0 : m.specificity}
spec
end
|
#eql?(other) ⇒ Boolean Also known as: ==
Checks equality between this and another object.
Subclasses should define #_eql?
rather than overriding this method,
which handles checking class equality and hash equality.
57 58 59 |
# File 'lib/sass/selector/abstract_sequence.rb', line 57
def eql?(other)
other.class == self.class && other.hash == self.hash && _eql?(other)
end
|
#has_placeholder? ⇒ Boolean
Whether or not this selector sequence contains a placeholder selector. Checks recursively.
64 65 66 67 |
# File 'lib/sass/selector/abstract_sequence.rb', line 64
def has_placeholder?
@has_placeholder ||=
members.any? {|m| m.is_a?(AbstractSequence) ? m.has_placeholder? : m.is_a?(Placeholder)}
end
|
#hash ⇒ Fixnum
Returns a hash code for this sequence.
Subclasses should define #_hash
rather than overriding this method,
which automatically handles memoizing the result.
46 47 48 |
# File 'lib/sass/selector/abstract_sequence.rb', line 46
def hash
@_hash ||= _hash
end
|
#specificity ⇒ Fixnum
Returns the specificity of the selector as an integer. The base is given by SPECIFICITY_BASE.
81 82 83 |
# File 'lib/sass/selector/abstract_sequence.rb', line 81
def specificity
_specificity(members)
end
|
#to_s ⇒ String
Converts the selector into a string. This is the standard selector string, along with any SassScript interpolation that may exist.
73 74 75 |
# File 'lib/sass/selector/abstract_sequence.rb', line 73
def to_s
to_a.map {|e| e.is_a?(Sass::Script::Node) ? "\#{#{e.to_sass}}" : e}.join
end
|